lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.9-6-g676d62c

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

python-stdnum branch master updated. 1.9-6-g676d62c



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  676d62c307e1456763b0dcd8e9149a8eaee7c3d5 (commit)
      from  65b5bfe6ff5be7735c351e4f501a45facafd110e (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=676d62c307e1456763b0dcd8e9149a8eaee7c3d5

commit 676d62c307e1456763b0dcd8e9149a8eaee7c3d5
Author: Esben Toke Christensen <esben.christensen@visma.com>
Date:   Thu May 24 10:29:12 2018 +0200

    Add iso11649 structured creditor reference
    
    Closes https://github.com/arthurdejong/python-stdnum/pull/72

diff --git a/stdnum/iso11649.py b/stdnum/iso11649.py
new file mode 100644
index 0000000..f176852
--- /dev/null
+++ b/stdnum/iso11649.py
@@ -0,0 +1,75 @@
+# iso11649.py - functions for performing the ISO 11649 checksum validation
+#               for structured creditor reference numbers
+#
+# Copyright (C) 2018 Esben Toke Christensen
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 USA
+
+"""ISO 11649 (Structured Creditor Reference).
+
+The ISO 11649 structured creditor number consists of 'RF' followed by two
+check digits and up to 21 digits. The number may contain letters.
+
+The reference number is validated by moving RF and the check digits to the
+end of the number, and checking that the ISO 7064 Mod 97, 10 checksum of this
+string is 1.
+
+More information:
+
+* https://en.wikipedia.org/wiki/Creditor_Reference
+
+>>> validate('RF18 5390 0754 7034')
+'RF18539007547034'
+>>> validate('RF18 5390 0754 70Y')
+'RF185390075470Y'
+>>> is_valid('RF18 5390 0754 7034')
+True
+>>> validate('RF17 5390 0754 7034')
+Traceback (most recent call last):
+    ...
+InvalidChecksum: ...
+"""
+
+from stdnum.exceptions import *
+from stdnum.iso7064 import mod_97_10
+from stdnum.util import clean
+
+
+def compact(number):
+    """Convert the number to the minimal representation. This strips the
+    number of any invalid separators and removes surrounding whitespace."""
+    return clean(number, ' -.,/:').upper().strip()
+
+
+def validate(number):
+    """Check if the number provided is a valid ISO 11649 structured creditor
+    reference number."""
+    number = compact(number)
+    if len(number) < 5 or len(number) > 25:
+        raise InvalidLength()
+    if not number.startswith('RF'):
+        raise InvalidFormat()
+    mod_97_10.validate(number[4:] + number[:4])
+    return number
+
+
+def is_valid(number):
+    """Check if the number provided is a valid ISO 11649 structured creditor
+    number. This checks the length, formatting and check digits."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False
diff --git a/tests/test_iso11649.doctest b/tests/test_iso11649.doctest
new file mode 100644
index 0000000..24cdd71
--- /dev/null
+++ b/tests/test_iso11649.doctest
@@ -0,0 +1,139 @@
+test_iso11649.doctest - more detailed doctests for the stdnum.iso11649 module
+
+Copyright (C) 2018 Esben Toke Christensen
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA
+
+
+This file contains more detailed doctests for the stdnum.iso11649 module. It
+tries to validate a number of numbers that have been generated online.
+
+>>> import stdnum.iso11649
+>>> from stdnum.exceptions import *
+
+
+The following numbers have been randomly generated at:
+https://www.mobilefish.com/services/creditor_reference/creditor_reference.php
+
+They should all be valid iso11649 structured creditor reference numbers
+
+
+>>> numbers = '''
+...
+... RF03SW3EZRUFBK
+... RF20QQHM7PAW61EOWO
+... RF206KCJWVH20
+... RF97XX5ZIC
+... RF66A4E7BF6OI8F23P9
+... RF888F7P5VQ8TOFTY3LZ
+... RF41778UFIFX6LGFHAX
+... RF8676YM2Q3UWC9
+... RF056TXFK
+... RF800PAG6O89TAU8M5H
+... RF20AN1IJBLFGA
+... RF23EF4UHBVNPLHKG3HZ9SGGT
+... RF79KDFLO48OJW9TSCUP7L
+... RF72YW
+... RF14GE30YOI8
+... RF95SVO25ZY0J
+... RF38W1PAA2QLIPIQVMAYLOH
+... RF80A0CPH
+... RF15O27ZC6D86DZGO
+... RF30VXZSLA8
+... RF87PBDPC22JTUPL98AYLOCK
+... RF14QS8OSM0SGZJHDAJI2S1
+... RF724P
+... RF0717UP2X0DO9UF6JGIPG8
+... RF42J8H8Y0VB5MXP1T24RHM3
+... RF70JNR
+... RF949BJ0SHL5OELQ0M16
+... RF75TR2ACY3PGL
+... RF0891RPECRY4EKAIWQK4UZUP
+... RF95079AYKHK4C6D8SF
+... RF63RPP1PYBH4K
+... RF28JGS
+... RF80I4
+... RF55IJ37T88JU5D0XUR6Z3N
+... RF08P
+... RF315S3SM4CXHLHPCCJULF36
+... RF25GKZ943I
+... RF10XHXROQ2ZS1
+... RF032KW3MG
+... RF03Z55N
+... RF93SYT6JCX9BF8STKZTF
+... RF910KN
+... RF4480GWBS4ON16IRYL7T5VN2
+... RF02YFL1INOWMIYT2AN
+... RF23PCSFK51V1XJALP
+... RF37K91OEQE0FMBZSBN
+... RF96QP1V07AYT
+... RF2939KX5US7LX3PAN1BNWC0H
+... RF02RLPTC78WPBRBZFWSU
+... RF85QEZRRD82
+... RF529
+... RF813OATFTW
+... RF02MT56MM6RK3NSA88RKVK
+... RF81WGYFUZZ0TWXHQK
+... RF21FYKWJSLDSEV5P8XGPE2
+... RF75B2UCA8B3KLEP4PNTJA
+... RF401ETPTNN0E83ASNVVNPWU
+... RF11JB
+... RF48T7F6BF5F4H9F9JG
+... RF68C
+... RF53AVDW8QM7M6A62
+... RF382LJGQV501HHZQ6ZS1
+... RF097
+... RF73XJXLAL
+... RF95B
+... RF57G
+... RF25282M4CZ5GHSGY3G85G
+... RF498F8Q7S17
+... RF701XP4QUW0YV62EI5DQ
+... RF16V1A2WFZ6U8RMNVLE
+... RF78DB1FAB
+... RF7522DRITKFXLL97L45F
+... RF11A8Z
+... RF04X2OY4TYLNF
+... RF607WBLIGJT8FLEPYJ
+... RF07YDRKBYAAJTZ9IEMA
+... RF186L
+... RF409UF6078QP
+... RF82K6F
+... RF28AGC
+... RF57G
+... RF1492GE4TE5I7
+... RF12EMD86TLG46QZT9Z0WA3I
+... RF056PZYKELS9JY35QWH11
+... RF288UQN77O6QWX5565
+... RF12Z7WS5GR9S4
+... RF17B6V83RKUJCKYSIV
+... RF489L8GK4
+... RF41FWLX
+... RF98FIKGWHA2AK04NMI
+... RF86V26RQ3Z
+... RF72813
+... RF59OG39OS05B0RBMT
+... RF67B3TIEBWV82
+... RF73UYAE6PKWKA7MMR62S0B
+... RF92DIALM
+... RF04J4
+... RF60OG76HU1XGBIHRU94K
+... RF22EM
+... RF67J7L
+...
+... '''
+>>> [x for x in numbers.splitlines() if x and not stdnum.iso11649.is_valid(x)]
+[]

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

Summary of changes:
 stdnum/iso11649.py          |  75 ++++++++++++++++++++++++
 tests/test_iso11649.doctest | 139 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 214 insertions(+)
 create mode 100644 stdnum/iso11649.py
 create mode 100644 tests/test_iso11649.doctest


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/