lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.0-6-g75bcef0

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

python-stdnum branch master updated. 1.0-6-g75bcef0



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  75bcef02660da492bcbaa1bad4a15a55f64a6df9 (commit)
       via  2574f89fd3b2ff12fe048e57ef3f9aba01a13315 (commit)
      from  9883c72176409c6a2cdb8a0f54fe4571446ddcb6 (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=75bcef02660da492bcbaa1bad4a15a55f64a6df9

commit 75bcef02660da492bcbaa1bad4a15a55f64a6df9
Author: Tony Bajan <tony.bajan@onefinestay.com>
Date:   Mon Feb 9 16:41:15 2015 +0000

    Add ISO 9362 (BIC) support

diff --git a/stdnum/iso9362.py b/stdnum/iso9362.py
new file mode 100644
index 0000000..e58ae52
--- /dev/null
+++ b/stdnum/iso9362.py
@@ -0,0 +1,86 @@
+# iso9362.py - functions for handling ISO 9362 Business identifier codes
+#
+# Copyright (C) 2015 Lifealike Ltd
+#
+# 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 9362 (Business identifier codes).
+
+An ISO 9362 identifier (also: BIC, BEI, or SWIFT code) uniquely
+identifies an institution. They are commonly used to route financial
+transactions.
+
+The code consists of a 4 letter institution code, a 2 letter country code,
+and a 2 character location code, optionally followed by a three character
+branch code.
+
+>>> validate('AGRIFRPP882')
+'AGRIFRPP882'
+>>> validate('AGRIFRPP')
+'AGRIFRPP'
+>>> validate('AGRIFRPP8')
+Traceback (most recent call last):
+    ...
+InvalidLength: ..
+>>> validate('AGRIF2PP')  # country code can't contain digits
+Traceback (most recent call last):
+    ...
+InvalidFormat: ..
+>>> format('agriFRPP')  # conventionally caps
+'AGRIFRPP'
+
+"""
+
+import re
+
+from stdnum.exceptions import *
+from stdnum.util import clean
+
+_bic_re = re.compile(r'^[a-z]{6}[0-9a-z]{2}([0-9a-z]{3})?$', re.IGNORECASE)
+
+
+def compact(number):
+    """Convert the number to the minimal representation. This strips the
+    number of any surrounding whitespace."""
+    number = clean(number).strip()
+    return number
+
+
+def validate(number):
+    """Checks to see if the number provided is a valid routing number. This
+    checks the length and characters in each position."""
+    number = compact(number)
+    if len(number) not in (8, 11):
+        raise InvalidLength()
+    match = _bic_re.search(number)
+    if not match:
+        raise InvalidFormat()
+    return number
+
+
+def is_valid(number):
+    """Checks to see if the number provided is a valid BIC. This checks the
+     length and characters in each position."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False
+
+
+def format(number):
+    """Reformat the passed number to the standard format."""
+    number = compact(number)
+    return number.upper()

http://arthurdejong.org/git/python-stdnum/commit/?id=2574f89fd3b2ff12fe048e57ef3f9aba01a13315

commit 2574f89fd3b2ff12fe048e57ef3f9aba01a13315
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Fri Apr 17 11:13:18 2015 +0200

    Raise InvalidComponent for unregistered IMSI

diff --git a/stdnum/imsi.py b/stdnum/imsi.py
index 7bed628..c5c3f1e 100644
--- a/stdnum/imsi.py
+++ b/stdnum/imsi.py
@@ -1,7 +1,7 @@
 # imsi.py - functions for handling International Mobile Subscriber Identity
 #           (IMSI) numbers
 #
-# Copyright (C) 2011, 2012, 2013 Arthur de Jong
+# Copyright (C) 2011-2015 Arthur de Jong
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -28,7 +28,7 @@ mobile phone users (the SIM).
 >>> validate('439011234567890')  # unknown MCC
 Traceback (most recent call last):
     ...
-InvalidFormat: ...
+InvalidComponent: ...
 >>> split('429011234567890')
 ('429', '01', '1234567890')
 >>> split('310150123456789')
@@ -67,7 +67,7 @@ def validate(number):
     if len(number) not in (14, 15):
         raise InvalidLength()
     if len(split(number)) != 3:
-        raise InvalidFormat()
+        raise InvalidComponent()
     return number
 
 

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

Summary of changes:
 stdnum/imsi.py                   |    6 ++--
 stdnum/{us/rtn.py => iso9362.py} |   71 +++++++++++++++++++-------------------
 2 files changed, 38 insertions(+), 39 deletions(-)
 copy stdnum/{us/rtn.py => iso9362.py} (55%)


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