diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2015-10-10 15:25:48 +0200 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2015-10-10 15:25:51 +0200 |
commit | 111b4fd7c91b5d3c7bce921a1436bc7d21d7cdfa (patch) | |
tree | b502cf5d8d339fee87938f1a2390d6fe668a798b /stdnum/isan.py | |
parent | 9f9d13cc1c1a25157494980cfc7c952411c1ea8c (diff) |
Fix handling of strip_check_digits in ISAN
This fixes the compact() function to honor the strip_check_digits
argument and does not validate the check digits if they are passed to
validate together with strip_check_digits.
Diffstat (limited to 'stdnum/isan.py')
-rw-r--r-- | stdnum/isan.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/stdnum/isan.py b/stdnum/isan.py index 24438f5..8edb091 100644 --- a/stdnum/isan.py +++ b/stdnum/isan.py @@ -70,7 +70,8 @@ def compact(number, strip_check_digits=True): of any valid separators and removes surrounding whitespace. The check digits are removed by default.""" number = list(split(number)) - number[2] = number[4] = '' + if strip_check_digits: + number[2] = number[4] = '' return ''.join(number) @@ -89,14 +90,15 @@ def validate(number, strip_check_digits=False, add_check_digits=False): if len(root) != 12 or len(episode) != 4 or len(check1) not in (0, 1) or \ len(version) not in (0, 8) or len(check1) not in (0, 1): raise InvalidLength() + # allow removing check digits + if strip_check_digits: + check1 = check2 = '' # check check digits if check1: mod_37_36.validate(root + episode + check1) if check2: mod_37_36.validate(root + episode + version + check2) - # remove or add check digits - if strip_check_digits: - check1 = check2 = '' + # add check digits if add_check_digits and not check1: check1 = mod_37_36.calc_check_digit(root + episode) if add_check_digits and not check2 and version: |