lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.4-18-ga9e5405

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 1.4-18-ga9e5405



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  a9e540510cec7581c16ce95e59822bff749af045 (commit)
      from  8ea76ba7ea52c3a33aae2e45d16aa41eacb6374b (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 -----------------------------------------------------------------
http://arthurdejong.org/git/python-stdnum/commit/?id=a9e540510cec7581c16ce95e59822bff749af045

commit a9e540510cec7581c16ce95e59822bff749af045
Author: Sergi Almacellas Abellana <sergi@koolpi.com>
Date:   Tue Nov 8 18:04:18 2016 +0100

    Implement calc_check_digits in SEPA Identifier of the Creditor (AT-02)

diff --git a/stdnum/eu/at_02.py b/stdnum/eu/at_02.py
index fa5d707..ca5973e 100644
--- a/stdnum/eu/at_02.py
+++ b/stdnum/eu/at_02.py
@@ -1,6 +1,6 @@
 # at_02.py - functions for handling AT-02 (SEPA Creditor identifier)
 #
-# Copyright (C) 2014 Sergi Almacellas Abellana
+# Copyright (C) 2014-2016 Sergi Almacellas Abellana
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -22,17 +22,20 @@
 This identifier is indicated in the ISO 20022 data element `Creditor Scheme
 Identification`. The creditor can be a legal entity, or an association that
 is not a legal entity, or a person.
+
 Ther first two digits contain the ISO country code, the nex two are check
-digitsi for the ISO 7064 Mod 97, 10 checksum, the next tree contain the
+digits for the ISO 7064 Mod 97, 10 checksum, the next tree contain the
 Creditor Bussines Code (or `ZZZ` if no bussness code used) and the remainder
 contain the country-specific identifier.
 
->>> validate('ES23ZZZ47690558N')
+>>> validate('ES 23 ZZZ 47690558N')
 'ES23ZZZ47690558N'
 >>> validate('ES2300047690558N')
 'ES2300047690558N'
 >>> compact('ES++()+23ZZZ4//7690558N')
 'ES23ZZZ47690558N'
+>>> calc_check_digits('ESXXZZZ47690558N')
+'23'
 """
 
 from stdnum.exceptions import *
@@ -44,15 +47,15 @@ _alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
 
 
 def compact(number):
-    """Convert the AT-02 number to the minimal representation. This strips the
-    number of any valid separators and removes invalid characters."""
+    """Convert the AT-02 number to the minimal representation. This strips
+    the number of any valid separators and removes invalid characters."""
     return clean(number, ' -/?:().m\'+"').strip().upper()
 
 
 def _to_base10(number):
     """Prepare the number to its base10 representation so it can be checked
-    with the ISO 7064 Mod 97, 10 algorithm. That means excluding positions
-    5 to 7 and moving the first four digits to the end"""
+    with the ISO 7064 Mod 97, 10 algorithm. That means excluding positions 5
+    to 7 and moving the first four digits to the end."""
     return ''.join(str(_alphabet.index(x)) for x in number[7:] + number[:4])
 
 
@@ -74,3 +77,12 @@ def is_valid(number):
         return bool(validate(number))
     except ValidationError:
         return False
+
+
+def calc_check_digits(number):
+    """Calculate the check digits that should be put in the number to make it
+    valid. Check digits in the supplied number are ignored."""
+    number = compact(number)
+    # replace check digits with placeholders
+    number = ''.join((number[:2], '00', number[4:]))
+    return mod_97_10.calc_check_digits(_to_base10(number)[:-2])

-----------------------------------------------------------------------

Summary of changes:
 stdnum/eu/at_02.py | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)


hooks/post-receive
-- 
python-stdnum
-- 
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
https://lists.arthurdejong.org/python-stdnum-commits/