lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.10-16-g9daa1b0

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

python-stdnum branch master updated. 1.10-16-g9daa1b0



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  9daa1b0cbcfdc74022387430c6f4229485e1ffa8 (commit)
       via  cc6ffec5ffe59bf4e1b1ba53cfcf4c39350546e3 (commit)
       via  be8e258fc09028eae2718d1b41a52aaccff1a300 (commit)
      from  0fc0c3055f03734eb6c29f67b4a49ff5117a7e52 (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=9daa1b0cbcfdc74022387430c6f4229485e1ffa8

commit 9daa1b0cbcfdc74022387430c6f4229485e1ffa8
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Feb 17 22:57:55 2019 +0100

    Fix typos

diff --git a/stdnum/ar/cbu.py b/stdnum/ar/cbu.py
index 31fe5d8..7339eba 100644
--- a/stdnum/ar/cbu.py
+++ b/stdnum/ar/cbu.py
@@ -20,10 +20,10 @@
 
 """CBU (Clave Bancaria Uniforme, Argentine bank account number).
 
-CBU it s a code of the Banks of Argentina to identify customer
-accounts. The number consists of 22 digits and consists of a 3 digit
-bank identiefyer, followed by a 4 digit branch identifyer, a check
-digit, a 13 digit account identifyer and another check digit.
+CBU it s a code of the Banks of Argentina to identify customer accounts. The
+number consists of 22 digits and consists of a 3 digit bank identifier,
+followed by a 4 digit branch identifier, a check digit, a 13 digit account
+identifier and another check digit.
 
 More information:
 
diff --git a/stdnum/at/uid.py b/stdnum/at/uid.py
index e11aa76..a3b103a 100644
--- a/stdnum/at/uid.py
+++ b/stdnum/at/uid.py
@@ -1,4 +1,4 @@
-# vat.py - functions for handling Austrian VAT numbers
+# uid.py - functions for handling Austrian VAT numbers
 #
 # Copyright (C) 2012, 2013 Arthur de Jong
 #
diff --git a/stdnum/iban.py b/stdnum/iban.py
index bdd0799..ccc5626 100644
--- a/stdnum/iban.py
+++ b/stdnum/iban.py
@@ -76,7 +76,7 @@ def calc_check_digits(number):
 
 
 def _struct_to_re(structure):
-    """Convert an IBAN structure to a refular expression that can be used
+    """Convert an IBAN structure to a regular expression that can be used
     to validate the number."""
     def conv(match):
         chars = {
diff --git a/update/iban.py b/update/iban.py
index 5cc0fa1..d199c40 100755
--- a/update/iban.py
+++ b/update/iban.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-# update/iban.py - script to donwload and parse data from the IBAN registry
+# update/iban.py - script to download and parse data from the IBAN registry
 #
 # Copyright (C) 2011-2018 Arthur de Jong
 #

https://arthurdejong.org/git/python-stdnum/commit/?id=cc6ffec5ffe59bf4e1b1ba53cfcf4c39350546e3

commit cc6ffec5ffe59bf4e1b1ba53cfcf4c39350546e3
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Feb 17 22:55:13 2019 +0100

    Improvements reported by pylint

diff --git a/stdnum/de/handelsregisternummer.py 
b/stdnum/de/handelsregisternummer.py
index c5b9041..540d394 100644
--- a/stdnum/de/handelsregisternummer.py
+++ b/stdnum/de/handelsregisternummer.py
@@ -2,7 +2,7 @@
 # coding: utf-8
 #
 # Copyright (C) 2015 Holvi Payment Services Oy
-# Copyright (C) 2018 Arthur de Jong
+# Copyright (C) 2018-2019 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
@@ -292,7 +292,7 @@ def validate(number, company_form=None):
     court = _courts.get(_to_min(court))
     if not court:
         raise InvalidComponent()
-    if type(court) != type(number):  # pragma: no cover (Python 2 code)
+    if not isinstance(court, type(number)):  # pragma: no cover (Python 2 code)
         court = court.decode('utf-8')
     if company_form and COMPANY_FORM_REGISTRY_TYPES.get(company_form) != 
registry:
         raise InvalidComponent()
diff --git a/stdnum/de/stnr.py b/stdnum/de/stnr.py
index a9b2026..d10ce37 100644
--- a/stdnum/de/stnr.py
+++ b/stdnum/de/stnr.py
@@ -2,7 +2,7 @@
 # coding: utf-8
 #
 # Copyright (C) 2017 Holvi Payment Services
-# Copyright (C) 2018 Arthur de Jong
+# Copyright (C) 2018-2019 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
@@ -88,7 +88,7 @@ def _clean_region(region):
         if x in 'abcdefghijklmnopqrstvwxyz')
 
 
-class _Format(object):
+class _Format():
 
     def __init__(self, fmt):
         self._fmt = fmt
@@ -137,7 +137,7 @@ def validate(number, region=None):
     if len(number) not in (10, 11, 13):
         raise InvalidLength()
     if not any(region_fmt.match(number) or country_fmt.match(number)
-               for region, region_fmt, country_fmt in _get_formats(region)):
+               for _region, region_fmt, country_fmt in _get_formats(region)):
         raise InvalidFormat()
     return number
 
@@ -163,7 +163,7 @@ def guess_regions(number):
 def to_regional_number(number):
     """Convert the number to a regional (10 or 11 digit) number."""
     number = compact(number)
-    for region, region_fmt, country_fmt in _get_formats():
+    for _region, region_fmt, country_fmt in _get_formats():
         m = country_fmt.match(number)
         if m:
             return region_fmt.replace(*m.groups())
@@ -176,7 +176,7 @@ def to_country_number(number, region=None):
     number = compact(number)
     formats = (
         (region_fmt.match(number), country_fmt)
-        for region, region_fmt, country_fmt in _get_formats(region))
+        for _region, region_fmt, country_fmt in _get_formats(region))
     formats = [
         (region_match, country_fmt)
         for region_match, country_fmt in formats
@@ -191,7 +191,7 @@ def to_country_number(number, region=None):
 def format(number, region=None):
     """Reformat the passed number to the standard format."""
     number = compact(number)
-    for region, region_fmt, country_fmt in _get_formats(region):
+    for _region, region_fmt, _country_fmt in _get_formats(region):
         m = region_fmt.match(number)
         if m:
             f, b, u, p = m.groups()
diff --git a/stdnum/do/cedula.py b/stdnum/do/cedula.py
index fce2f09..36cae57 100644
--- a/stdnum/do/cedula.py
+++ b/stdnum/do/cedula.py
@@ -1,7 +1,7 @@
 # cedula.py - functions for handling Dominican Republic national identifier
 # coding: utf-8
 #
-# Copyright (C) 2015-2018 Arthur de Jong
+# Copyright (C) 2015-2019 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
@@ -199,7 +199,7 @@ def check_dgii(number, timeout=30):  # pragma: no cover
     # this function isn't automatically tested because it would require
     # network access for the tests and unnecessarily load the online service
     # we use the RNC implementation and change the rnc result to cedula
-    result = rnc.check_dgii(number)
+    result = rnc.check_dgii(number, timeout)
     if result and 'rnc' in result:
         result['cedula'] = result.pop('rnc')
     return result
diff --git a/stdnum/numdb.py b/stdnum/numdb.py
index 2b1a6e9..503f539 100644
--- a/stdnum/numdb.py
+++ b/stdnum/numdb.py
@@ -1,6 +1,6 @@
 # numdb.py - module for handling hierarchically organised numbers
 #
-# Copyright (C) 2010-2017 Arthur de Jong
+# Copyright (C) 2010-2019 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
@@ -106,7 +106,7 @@ _open_databases = {}
 # (there is no expected ordering within the list)
 
 
-class NumDB(object):
+class NumDB():
     """Number database."""
 
     def __init__(self):

https://arthurdejong.org/git/python-stdnum/commit/?id=be8e258fc09028eae2718d1b41a52aaccff1a300

commit be8e258fc09028eae2718d1b41a52aaccff1a300
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Feb 17 22:16:24 2019 +0100

    Add Cuban número de identidad

diff --git a/stdnum/cu/__init__.py b/stdnum/cu/__init__.py
new file mode 100644
index 0000000..aec2e46
--- /dev/null
+++ b/stdnum/cu/__init__.py
@@ -0,0 +1,21 @@
+# __init__.py - collection of Cuban numbers
+# coding: utf-8
+#
+# Copyright (C) 2019 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
+# 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
+
+"""Collection of Cuban numbers."""
diff --git a/stdnum/cu/ni.py b/stdnum/cu/ni.py
new file mode 100644
index 0000000..78e4df1
--- /dev/null
+++ b/stdnum/cu/ni.py
@@ -0,0 +1,109 @@
+# ni.py - functions for handling Cuban identity card numbers
+# coding: utf-8
+#
+# Copyright (C) 2019 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
+# 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
+
+"""NI (Número de identidad, Cuban identity card numbers).
+
+Número de carnet de identidad is the Cuban national identifier that is
+assigned to residents. The number consists of 11 digits and include the date
+of birth of the person and gender.
+
+More information:
+
+* http://www.postdata.club/issues/201609/es-usted-unico-en-cuba.html
+
+>>> validate('91021027775')
+'91021027775'
+>>> validate('9102102777A')
+Traceback (most recent call last):
+    ...
+InvalidFormat: ...
+>>> get_birth_date('91021027775')
+datetime.date(1991, 2, 10)
+>>> get_gender('91021027775')
+'F'
+>>> get_birth_date('72062506561')
+datetime.date(1972, 6, 25)
+>>> get_gender('72062506561')
+'M'
+>>> get_birth_date('85020291531')
+datetime.date(1885, 2, 2)
+>>> get_birth_date('02023061531')
+Traceback (most recent call last):
+    ...
+InvalidComponent: ...
+"""
+
+import datetime
+
+from stdnum.exceptions import *
+from stdnum.util import clean
+
+
+def compact(number):
+    """Convert the number to the minimal representation. This strips
+    surrounding whitespace and separation dash."""
+    return clean(number, ' ').strip()
+
+
+def get_birth_date(number):
+    """Split the date parts from the number and return the date of birth."""
+    number = compact(number)
+    year = int(number[0:2])
+    month = int(number[2:4])
+    day = int(number[4:6])
+    if number[6] == '9':
+        year += 1800
+    elif '0' <= number[6] <= '5':
+        year += 1900
+    else:
+        year += 2000
+    try:
+        return datetime.date(year, month, day)
+    except ValueError:
+        raise InvalidComponent()
+
+
+def get_gender(number):
+    """Get the gender (M/F) from the person's NI."""
+    number = compact(number)
+    if int(number[9]) % 2:
+        return 'F'
+    else:
+        return 'M'
+
+
+def validate(number):
+    """Check if the number is a valid NI. This checks the length, formatting
+    and check digit."""
+    number = compact(number)
+    if len(number) != 11:
+        raise InvalidLength()
+    if not number.isdigit():
+        raise InvalidFormat()
+    get_birth_date(number)
+    return number
+
+
+def is_valid(number):
+    """Check if the number is a valid NI."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False

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

Summary of changes:
 stdnum/ar/cbu.py                   |   8 +--
 stdnum/at/uid.py                   |   2 +-
 stdnum/{ie => cu}/__init__.py      |   6 +-
 stdnum/cu/ni.py                    | 109 +++++++++++++++++++++++++++++++++++++
 stdnum/de/handelsregisternummer.py |   4 +-
 stdnum/de/stnr.py                  |  12 ++--
 stdnum/do/cedula.py                |   4 +-
 stdnum/iban.py                     |   2 +-
 stdnum/numdb.py                    |   4 +-
 update/iban.py                     |   2 +-
 10 files changed, 131 insertions(+), 22 deletions(-)
 copy stdnum/{ie => cu}/__init__.py (86%)
 create mode 100644 stdnum/cu/ni.py


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/