lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.7-12-ga6ae1d0

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

python-stdnum branch master updated. 1.7-12-ga6ae1d0



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  a6ae1d0d2bb8f28fef71678f70951a769086c78b (commit)
      from  6be1754ace72b849bbd382cfc1f23ab79d880ed8 (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=a6ae1d0d2bb8f28fef71678f70951a769086c78b

commit a6ae1d0d2bb8f28fef71678f70951a769086c78b
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Thu Nov 2 18:52:17 2017 +0100

    Rename stdnum.iso9362 to stdnum.bic
    
    The new name is more descriptive and easier to remember. This makes
    stdnum.iso9362 a compatibility module that can be imported with the old
    name but provides a deprecation warning.

diff --git a/docs/index.rst b/docs/index.rst
index dd1fbcc..822c6d2 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -98,6 +98,7 @@ Available formats
    bg.egn
    bg.pnf
    bg.vat
+   bic
    br.cnpj
    br.cpf
    ca.bn
@@ -169,7 +170,6 @@ Available formats
    isin
    ismn
    iso6346
-   iso9362
    issn
    it.codicefiscale
    it.iva
diff --git a/docs/stdnum.bic.rst b/docs/stdnum.bic.rst
new file mode 100644
index 0000000..15ed444
--- /dev/null
+++ b/docs/stdnum.bic.rst
@@ -0,0 +1,5 @@
+stdnum.bic
+==========
+
+.. automodule:: stdnum.bic
+   :members:
\ No newline at end of file
diff --git a/docs/stdnum.iso9362.rst b/docs/stdnum.iso9362.rst
deleted file mode 100644
index d8749e8..0000000
--- a/docs/stdnum.iso9362.rst
+++ /dev/null
@@ -1,5 +0,0 @@
-stdnum.iso9362
-==============
-
-.. automodule:: stdnum.iso9362
-   :members:
\ No newline at end of file
diff --git a/stdnum/iso9362.py b/stdnum/bic.py
similarity index 94%
copy from stdnum/iso9362.py
copy to stdnum/bic.py
index 80006ad..52aae42 100644
--- a/stdnum/iso9362.py
+++ b/stdnum/bic.py
@@ -1,6 +1,7 @@
-# iso9362.py - functions for handling ISO 9362 Business identifier codes
+# bic.py - functions for handling ISO 9362 Business identifier codes
 #
 # Copyright (C) 2015 Lifealike Ltd
+# Copyright (C) 2017 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
@@ -17,7 +18,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301 USA
 
-"""ISO 9362 (Business identifier codes).
+"""BIC (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
diff --git a/stdnum/iso9362.py b/stdnum/iso9362.py
index 80006ad..321e531 100644
--- a/stdnum/iso9362.py
+++ b/stdnum/iso9362.py
@@ -1,6 +1,6 @@
-# iso9362.py - functions for handling ISO 9362 Business identifier codes
+# iso9362.py - compatibility module for stdnum.bic
 #
-# Copyright (C) 2015 Lifealike Ltd
+# Copyright (C) 2017 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
@@ -17,67 +17,17 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301 USA
 
-"""ISO 9362 (Business identifier codes).
+# flake8: noqa
 
-An ISO 9362 identifier (also: BIC, BEI, or SWIFT code) uniquely
-identifies an institution. They are commonly used to route financial
-transactions.
+import sys
+import warnings
 
-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'
+warnings.warn(
+    'The stdnum.iso9362 module has been renamed, use stdnum.bic instead.',
+    DeprecationWarning, stacklevel=2)
 
-"""
 
-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})?$')
-
-
-def compact(number):
-    """Convert the number to the minimal representation. This strips the
-    number of any surrounding whitespace."""
-    return clean(number).strip().upper()
-
-
-def validate(number):
-    """Check if the number 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):
-    """Check if the number provided is a valid BIC."""
-    try:
-        return bool(validate(number))
-    except ValidationError:
-        return False
-
-
-def format(number):
-    """Reformat the number to the standard presentation format."""
-    return compact(number)
+# We ensure that stdnum.bic is exposed in this module's place
+import stdnum.bic
+sys.modules[__name__] = stdnum.bic
diff --git a/stdnum/util.py b/stdnum/util.py
index 7033047..58dc8d5 100644
--- a/stdnum/util.py
+++ b/stdnum/util.py
@@ -30,6 +30,7 @@ import pydoc
 import re
 import sys
 import unicodedata
+import warnings
 
 from stdnum.exceptions import *
 
@@ -129,15 +130,18 @@ def clean(number, deletechars=''):
 
 
 def get_number_modules(base='stdnum'):
-    """Yield all the module and package names under the specified module."""
+    """Yield all the number validation modules under the specified module."""
     __import__(base)
     module = sys.modules[base]
-    for _loader, name, _is_pkg in pkgutil.walk_packages(
-            module.__path__, module.__name__ + '.'):
-        __import__(name)
-        module = sys.modules[name]
-        if hasattr(module, 'validate'):
-            yield module
+    # we ignore deprecation warnings from transitional modules
+    with warnings.catch_warnings():
+        warnings.filterwarnings('ignore', category=DeprecationWarning, 
module='stdnum\..*')
+        for _loader, name, _is_pkg in pkgutil.walk_packages(
+                module.__path__, module.__name__ + '.'):
+            __import__(name)
+            module = sys.modules[name]
+            if hasattr(module, 'validate') and module.__name__ == name:
+                yield module
 
 
 def get_module_name(module):

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

Summary of changes:
 docs/index.rst                |  2 +-
 docs/stdnum.bic.rst           |  5 +++
 docs/stdnum.iso9362.rst       |  5 ---
 stdnum/{iso9362.py => bic.py} |  5 +--
 stdnum/iso9362.py             | 72 +++++++------------------------------------
 stdnum/util.py                | 18 ++++++-----
 6 files changed, 31 insertions(+), 76 deletions(-)
 create mode 100644 docs/stdnum.bic.rst
 delete mode 100644 docs/stdnum.iso9362.rst
 copy stdnum/{iso9362.py => bic.py} (94%)


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/