python-stdnum branch master updated. 1.17-21-geae1dd2
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum branch master updated. 1.17-21-geae1dd2
- 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.17-21-geae1dd2
- Date: Mon, 15 Aug 2022 14:10:37 +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 eae1dd298e56b565af394d6fc85ead89fbbf8565 (commit)
from c5595c7e80277bbf2102f293c1f4fbcec07f7101 (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=eae1dd298e56b565af394d6fc85ead89fbbf8565
commit eae1dd298e56b565af394d6fc85ead89fbbf8565
Author: Arthur de Jong <arthur@arthurdejong.org>
Date: Mon Aug 15 13:59:26 2022 +0200
Use str.zfill() for padding leading zeros
diff --git a/stdnum/ch/esr.py b/stdnum/ch/esr.py
index 862df78..8d62380 100644
--- a/stdnum/ch/esr.py
+++ b/stdnum/ch/esr.py
@@ -92,7 +92,6 @@ def is_valid(number):
def format(number):
"""Reformat the number to the standard presentation format."""
- number = 27 * '0' + compact(number)
- number = number[-27:]
+ number = compact(number).zfill(27)
return number[:2] + ' ' + ' '.join(
number[i:i + 5] for i in range(2, len(number), 5))
diff --git a/stdnum/il/idnr.py b/stdnum/il/idnr.py
index 544d6df..545f5fc 100644
--- a/stdnum/il/idnr.py
+++ b/stdnum/il/idnr.py
@@ -51,9 +51,7 @@ from stdnum.util import clean, isdigits
def compact(number):
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
- number = clean(number, ' -').strip()
- # pad with leading zeroes
- return (9 - len(number)) * '0' + number
+ return clean(number, ' -').strip().zfill(9)
def validate(number):
diff --git a/stdnum/isin.py b/stdnum/isin.py
index e1bbfca..1d48f88 100644
--- a/stdnum/isin.py
+++ b/stdnum/isin.py
@@ -129,6 +129,5 @@ def is_valid(number):
def from_natid(country_code, number):
"""Generate an ISIN from a national security identifier."""
- number = compact(number)
- number = country_code.upper() + (9 - len(number)) * '0' + number
+ number = country_code.upper() + compact(number).zfill(9)
return number + calc_check_digit(number)
diff --git a/stdnum/nl/bsn.py b/stdnum/nl/bsn.py
index b869100..c3b3583 100644
--- a/stdnum/nl/bsn.py
+++ b/stdnum/nl/bsn.py
@@ -51,9 +51,7 @@ from stdnum.util import clean, isdigits
def compact(number):
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
- number = clean(number, ' -.').strip()
- # pad with leading zeroes
- return (9 - len(number)) * '0' + number
+ return clean(number, ' -.').strip().zfill(9)
def checksum(number):
diff --git a/stdnum/no/kontonr.py b/stdnum/no/kontonr.py
index 1a466e0..addc767 100644
--- a/stdnum/no/kontonr.py
+++ b/stdnum/no/kontonr.py
@@ -96,8 +96,7 @@ def to_iban(number):
def format(number):
"""Reformat the number to the standard presentation format."""
- number = compact(number)
- number = (11 - len(number)) * '0' + number
+ number = compact(number).zfill(11)
return '.'.join([
number[:4],
number[4:6],
diff --git a/stdnum/nz/ird.py b/stdnum/nz/ird.py
index 0e9307a..6bd313b 100644
--- a/stdnum/nz/ird.py
+++ b/stdnum/nz/ird.py
@@ -66,7 +66,7 @@ def calc_check_digit(number):
primary_weights = (3, 2, 7, 6, 5, 4, 3, 2)
secondary_weights = (7, 4, 3, 2, 5, 2, 7, 6)
# pad with leading zeros
- number = (8 - len(number)) * '0' + number
+ number = number.zfill(8)
s = -sum(w * int(n) for w, n in zip(primary_weights, number)) % 11
if s != 10:
return str(s)
diff --git a/stdnum/ro/cui.py b/stdnum/ro/cui.py
index 8e88840..fbfad98 100644
--- a/stdnum/ro/cui.py
+++ b/stdnum/ro/cui.py
@@ -59,7 +59,7 @@ def compact(number):
def calc_check_digit(number):
"""Calculate the check digit."""
weights = (7, 5, 3, 2, 1, 7, 5, 3, 2)
- number = (9 - len(number)) * '0' + number
+ number = number.zfill(9)
check = 10 * sum(w * int(n) for w, n in zip(weights, number))
return str(check % 11 % 10)
-----------------------------------------------------------------------
Summary of changes:
stdnum/ch/esr.py | 3 +--
stdnum/il/idnr.py | 4 +---
stdnum/isin.py | 3 +--
stdnum/nl/bsn.py | 4 +---
stdnum/no/kontonr.py | 3 +--
stdnum/nz/ird.py | 2 +-
stdnum/ro/cui.py | 2 +-
7 files changed, 7 insertions(+), 14 deletions(-)
hooks/post-receive
--
python-stdnum
- python-stdnum branch master updated. 1.17-21-geae1dd2,
Commits of the python-stdnum project