python-stdnum branch master updated. 1.20-31-g8283dbb
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum branch master updated. 1.20-31-g8283dbb
- From: Commits of the python-stdnum project <python-stdnum-commits [at] lists.arthurdejong.org>
- To: python-stdnum-commits [at] lists.arthurdejong.org
- Reply-to: python-stdnum-users [at] lists.arthurdejong.org, python-stdnum-commits [at] lists.arthurdejong.org
- Subject: python-stdnum branch master updated. 1.20-31-g8283dbb
- Date: Mon, 21 Apr 2025 16:46:30 +0200 (CEST)
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".
The branch, master has been updated
via 8283dbb08dd5e8c720a0ece468b051a921334a07 (commit)
via 6b9bbe26d09f9966003e398357be51d56c8f9051 (commit)
from 3542c064b8116af25c9f6de2e418b9778f92f571 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-stdnum/commit/?id=8283dbb08dd5e8c720a0ece468b051a921334a07
commit 8283dbb08dd5e8c720a0ece468b051a921334a07
Author: David Salvisberg <david.salvisberg@seantis.ch>
Date: Thu Mar 13 14:15:54 2025 +0100
Explicity return None
As per PEP 8.
See https://peps.python.org/pep-0008/
diff --git a/stdnum/be/bis.py b/stdnum/be/bis.py
index 77876fe..fc59cf5 100644
--- a/stdnum/be/bis.py
+++ b/stdnum/be/bis.py
@@ -123,3 +123,4 @@ def get_gender(number):
number = compact(number)
if int(number[2:4]) >= 40:
return nn.get_gender(number)
+ return None
diff --git a/stdnum/be/nn.py b/stdnum/be/nn.py
index 135d883..6cf64af 100644
--- a/stdnum/be/nn.py
+++ b/stdnum/be/nn.py
@@ -184,6 +184,7 @@ def get_birth_date(number):
year, month, day = _get_birth_date_parts(compact(number))
if year and month and day:
return datetime.date(year, month, day)
+ return None
def get_gender(number):
diff --git a/stdnum/be/ssn.py b/stdnum/be/ssn.py
index 65045c1..e22cfd8 100644
--- a/stdnum/be/ssn.py
+++ b/stdnum/be/ssn.py
@@ -126,6 +126,7 @@ def guess_type(number):
for mod in _ssn_modules:
if mod.is_valid(number):
return mod.__name__.rsplit('.', 1)[-1]
+ return None
def format(number):
@@ -153,3 +154,4 @@ def get_gender(number):
for mod in _ssn_modules:
if mod.is_valid(number):
return mod.get_gender(number)
+ return None
diff --git a/stdnum/de/handelsregisternummer.py
b/stdnum/de/handelsregisternummer.py
index cce3043..012e86f 100644
--- a/stdnum/de/handelsregisternummer.py
+++ b/stdnum/de/handelsregisternummer.py
@@ -373,4 +373,4 @@ def check_offeneregister(number, timeout=30, verify=True):
# pragma: no cover (
json = response.json()
return dict(zip(json['columns'], json['rows'][0]))
except (KeyError, IndexError) as e: # noqa: F841
- return # number not found
+ return None # number not found
diff --git a/stdnum/do/ncf.py b/stdnum/do/ncf.py
index 39c17a7..b17760e 100644
--- a/stdnum/do/ncf.py
+++ b/stdnum/do/ncf.py
@@ -240,3 +240,4 @@ def check_dgii(rnc, ncf, buyer_rnc=None,
security_code=None, timeout=30, verify=
[x.text.strip() for x in result.findall('.//th') if x.text],
[x.text.strip() for x in result.findall('.//td/span') if x.text]))
return _convert_result(data)
+ return None
diff --git a/stdnum/do/rnc.py b/stdnum/do/rnc.py
index fdb4f04..10c5b43 100644
--- a/stdnum/do/rnc.py
+++ b/stdnum/do/rnc.py
@@ -153,7 +153,7 @@ def check_dgii(number, timeout=30, verify=True): # pragma:
no cover
if result and 'GetContribuyentesResult' in result:
result = result['GetContribuyentesResult'] # PySimpleSOAP only
if result == '0':
- return
+ return None
result = [x for x in result.split('@@@')]
return _convert_result(result[0])
diff --git a/stdnum/eu/vat.py b/stdnum/eu/vat.py
index cb5d417..c1b6d00 100644
--- a/stdnum/eu/vat.py
+++ b/stdnum/eu/vat.py
@@ -68,7 +68,7 @@ def _get_cc_module(cc):
if cc == 'el':
cc = 'gr'
if cc not in MEMBER_STATES:
- return
+ return None
if cc == 'xi':
cc = 'gb'
if cc not in _country_modules:
diff --git a/stdnum/pk/cnic.py b/stdnum/pk/cnic.py
index 965ada0..495399d 100644
--- a/stdnum/pk/cnic.py
+++ b/stdnum/pk/cnic.py
@@ -63,6 +63,7 @@ def get_gender(number):
return 'M'
elif number[-1] in '2468':
return 'F'
+ return None
# Valid Province IDs
diff --git a/stdnum/util.py b/stdnum/util.py
index 081c3ba..4da281e 100644
--- a/stdnum/util.py
+++ b/stdnum/util.py
@@ -229,7 +229,7 @@ def get_cc_module(cc, name):
mod = __import__('stdnum.%s' % cc, globals(), locals(), [name])
return getattr(mod, name, None)
except ImportError:
- return
+ return None
# this is a cache of SOAP clients
https://arthurdejong.org/git/python-stdnum/commit/?id=6b9bbe26d09f9966003e398357be51d56c8f9051
commit 6b9bbe26d09f9966003e398357be51d56c8f9051
Author: David Salvisberg <david.salvisberg@seantis.ch>
Date: Thu Mar 13 14:15:54 2025 +0100
Small code cleanups
diff --git a/stdnum/be/iban.py b/stdnum/be/iban.py
index ca740db..83c3669 100644
--- a/stdnum/be/iban.py
+++ b/stdnum/be/iban.py
@@ -74,9 +74,7 @@ def info(number):
def to_bic(number):
"""Return the BIC for the bank that this number refers to."""
- bic = info(number).get('bic')
- if bic:
- return str(bic)
+ return info(number).get('bic')
def validate(number):
diff --git a/stdnum/be/nn.py b/stdnum/be/nn.py
index 6dea86b..135d883 100644
--- a/stdnum/be/nn.py
+++ b/stdnum/be/nn.py
@@ -182,7 +182,7 @@ def get_birth_month(number):
def get_birth_date(number):
"""Return the date of birth."""
year, month, day = _get_birth_date_parts(compact(number))
- if None not in (year, month, day):
+ if year and month and day:
return datetime.date(year, month, day)
diff --git a/stdnum/cz/bankaccount.py b/stdnum/cz/bankaccount.py
index 3100c8a..92c2c6e 100644
--- a/stdnum/cz/bankaccount.py
+++ b/stdnum/cz/bankaccount.py
@@ -97,9 +97,7 @@ def info(number):
def to_bic(number):
"""Return the BIC for the bank that this number refers to."""
- bic = info(number).get('bic')
- if bic:
- return str(bic)
+ return info(number).get('bic')
def _calc_checksum(number):
diff --git a/stdnum/es/cups.py b/stdnum/es/cups.py
index cbbcacd..88ec9d9 100644
--- a/stdnum/es/cups.py
+++ b/stdnum/es/cups.py
@@ -94,8 +94,8 @@ def validate(number):
raise InvalidComponent()
if not isdigits(number[2:18]):
raise InvalidFormat()
- if number[20:]:
- pnumber, ptype = number[20:]
+ if len(number) == 22:
+ pnumber, ptype = number[20], number[21]
if not isdigits(pnumber):
raise InvalidFormat()
if ptype not in 'FPRCXYZ':
diff --git a/stdnum/gs1_128.py b/stdnum/gs1_128.py
index 473a68c..ba41051 100644
--- a/stdnum/gs1_128.py
+++ b/stdnum/gs1_128.py
@@ -197,7 +197,7 @@ def info(number, separator=''):
number = number[len(ai):]
# figure out the value part
value = number[:_max_length(info['format'], info['type'])]
- if separator and info.get('fnc1', False):
+ if separator and info.get('fnc1'):
idx = number.find(separator)
if idx > 0:
value = number[:idx]
@@ -243,7 +243,7 @@ def encode(data, separator='', parentheses=False):
mod.validate(value)
value = _encode_value(info['format'], info['type'], value)
# store variable-sized values separate from fixed-size values
- if info.get('fnc1', False):
+ if info.get('fnc1'):
variable_values.append((ai_fmt % ai, info['format'], info['type'],
value))
else:
fixed_values.append(ai_fmt % ai + value)
diff --git a/stdnum/pk/cnic.py b/stdnum/pk/cnic.py
index cd1381f..965ada0 100644
--- a/stdnum/pk/cnic.py
+++ b/stdnum/pk/cnic.py
@@ -78,7 +78,7 @@ PROVINCES = {
def get_province(number):
- """Get the person's birth gender ('M' or 'F')."""
+ """Get the person's province."""
number = compact(number)
return PROVINCES.get(number[0])
diff --git a/stdnum/vatin.py b/stdnum/vatin.py
index f7ee12b..d05e8f7 100644
--- a/stdnum/vatin.py
+++ b/stdnum/vatin.py
@@ -23,7 +23,7 @@
The number VAT identification number (VATIN) is an identifier used in many
countries. It starts with an ISO 3166-1 alpha-2 (2 letters) country code
(except for Greece, which uses EL, instead of GR) and is followed by the
-country-specific the identifier.
+country-specific identifier.
This module supports all VAT numbers that are supported in python-stdnum.
@@ -65,9 +65,10 @@ def _get_cc_module(cc):
raise InvalidFormat()
if cc not in _country_modules:
_country_modules[cc] = get_cc_module(cc, 'vat')
- if not _country_modules[cc]:
+ module = _country_modules[cc]
+ if not module:
raise InvalidComponent() # unknown/unsupported country code
- return _country_modules[cc]
+ return module
def compact(number):
diff --git a/stdnum/verhoeff.py b/stdnum/verhoeff.py
index b6b0f20..401fb1c 100644
--- a/stdnum/verhoeff.py
+++ b/stdnum/verhoeff.py
@@ -77,11 +77,8 @@ _permutation_table = (
def checksum(number):
"""Calculate the Verhoeff checksum over the provided number. The checksum
is returned as an int. Valid numbers should have a checksum of 0."""
- # transform number list
- number = tuple(int(n) for n in reversed(str(number)))
- # calculate checksum
check = 0
- for i, n in enumerate(number):
+ for i, n in enumerate(int(n) for n in reversed(str(number))):
check = _multiplication_table[check][_permutation_table[i % 8][n]]
return check
diff --git a/tests/test_be_iban.doctest b/tests/test_be_iban.doctest
index eee71ec..454dfd4 100644
--- a/tests/test_be_iban.doctest
+++ b/tests/test_be_iban.doctest
@@ -37,6 +37,15 @@ Traceback (most recent call last):
InvalidChecksum: ...
+Some bank account numbers don't have a BIC.
+(this is a constructed bank account number, no actual one was found in the
wild)
+
+>>> iban.validate('BE45102000000089')
+'BE45102000000089'
+>>> iban.to_bic('BE45102000000089') is None
+True
+
+
These should all be valid numbers combined with the appropriate BIC code for
the IBAN.
-----------------------------------------------------------------------
Summary of changes:
stdnum/be/bis.py | 1 +
stdnum/be/iban.py | 4 +---
stdnum/be/nn.py | 3 ++-
stdnum/be/ssn.py | 2 ++
stdnum/cz/bankaccount.py | 4 +---
stdnum/de/handelsregisternummer.py | 2 +-
stdnum/do/ncf.py | 1 +
stdnum/do/rnc.py | 2 +-
stdnum/es/cups.py | 4 ++--
stdnum/eu/vat.py | 2 +-
stdnum/gs1_128.py | 4 ++--
stdnum/pk/cnic.py | 3 ++-
stdnum/util.py | 2 +-
stdnum/vatin.py | 7 ++++---
stdnum/verhoeff.py | 5 +----
tests/test_be_iban.doctest | 9 +++++++++
16 files changed, 32 insertions(+), 23 deletions(-)
hooks/post-receive
--
python-stdnum
- python-stdnum branch master updated. 1.20-31-g8283dbb,
Commits of the python-stdnum project