lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.3-6-g0a2f39e

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

python-stdnum branch master updated. 1.3-6-g0a2f39e



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  0a2f39e34e0ea19efc61ce5eb54e5c46012d858d (commit)
       via  21269472475774e94faf6dea72cc3fcc700d69b8 (commit)
       via  e28b5e10acc6050f016c1171c35b10354927a8b2 (commit)
      from  feab9177256f77da9413a397016691fad177be79 (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=0a2f39e34e0ea19efc61ce5eb54e5c46012d858d

commit 0a2f39e34e0ea19efc61ce5eb54e5c46012d858d
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Mon May 9 19:52:43 2016 +0200

    Add United Kingdom NHS number
    
    Add module for United Kingdom National Health Service patient
    identifier.

diff --git a/stdnum/gb/nhs.py b/stdnum/gb/nhs.py
new file mode 100644
index 0000000..3773afc
--- /dev/null
+++ b/stdnum/gb/nhs.py
@@ -0,0 +1,85 @@
+# nhs.py - functions for handling United Kingdom NHS numbers
+#
+# Copyright (C) 2012-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
+# 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
+
+"""NHS (United Kingdom National Health Service patient identifier).
+
+The NHS number is used by the NHS (National Health Service) and its partners
+to uniquely identify patients. The number is used in England, Wales and the
+Isle of Man. The number is assigned at birth and consists of 10 digits where
+the final digit is a check digit.
+
+More information:
+
+* https://en.wikipedia.org/wiki/NHS_number
+* http://www.nhs.uk/NHSEngland/thenhs/records/nhs-number/
+* http://systems.hscic.gov.uk/nhsnumber
+* 
http://www.datadictionary.nhs.uk/data_dictionary/attributes/n/nhs/nhs_number_de.asp
+
+>>> validate('943-476-5870')
+'9434765870'
+>>> validate('9434765871')  # invalid check digit
+Traceback (most recent call last):
+    ...
+InvalidChecksum: ...
+>>> format('9434765870')
+'943 476 5870'
+"""
+
+from stdnum.util import clean
+from stdnum.exceptions import *
+
+
+def compact(number):
+    """Convert the number to the minimal representation. This strips the
+    number of any valid separators and removes surrounding whitespace."""
+    return clean(number, ' -').strip()
+
+
+def checksum(number):
+    """Calculate the checksum. The checksum is only used for the 9 digits
+    of the number and the result can either be 0 or 42."""
+    return sum(i * int(n) for i, n in enumerate(reversed(number), 1)) % 11
+
+
+def validate(number):
+    """Checks to see if the number provided is valid. This checks the length
+    and check digit."""
+    number = compact(number)
+    if not number.isdigit():
+        raise InvalidFormat()
+    if len(number) != 10:
+        raise InvalidLength()
+    if checksum(number) != 0:
+        raise InvalidChecksum()
+    return number
+
+
+def is_valid(number):
+    """Checks to see if the number provided is valid. This checks the length
+    and check digit."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False
+
+
+def format(number, separator=' '):
+    """Reformat the passed number to the standard format."""
+    number = compact(number)
+    return separator.join((number[0:3], number[3:6], number[6:]))

http://arthurdejong.org/git/python-stdnum/commit/?id=21269472475774e94faf6dea72cc3fcc700d69b8

commit 21269472475774e94faf6dea72cc3fcc700d69b8
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Mon May 9 19:39:18 2016 +0200

    Read numdb files in context manager
    
    This ensures that the file is explicitly closed in the function to avoid
    "unclosed file" warnings.
    
    See: https://github.com/arthurdejong/python-stdnum/issues/33

diff --git a/stdnum/numdb.py b/stdnum/numdb.py
index 0a2e155..c8cbc3c 100644
--- a/stdnum/numdb.py
+++ b/stdnum/numdb.py
@@ -199,6 +199,6 @@ def get(name):
     if name not in _open_databases:
         import codecs
         reader = codecs.getreader('utf-8')
-        db = read(reader(resource_stream(__name__, name + '.dat')))
-        _open_databases[name] = db
+        with reader(resource_stream(__name__, name + '.dat')) as fp:
+            _open_databases[name] = db = read(fp)
     return _open_databases[name]

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

commit e28b5e10acc6050f016c1171c35b10354927a8b2
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Mon Apr 11 22:58:17 2016 +0200

    Make more information links consistent
    
    Also fix a docstring in stdnum.nl.bsn and add a pointer to
    stdnum.nl.onderwijsnummer.

diff --git a/stdnum/ch/uid.py b/stdnum/ch/uid.py
index 6622f50..62800bc 100644
--- a/stdnum/ch/uid.py
+++ b/stdnum/ch/uid.py
@@ -27,9 +27,10 @@ protected with a simple checksum.
 This module only supports the "new" format that was introduced in 2011 which
 completely replaced the "old" 6-digit format in 2014.
 
-More information is available at:
-  https://www.uid.admin.ch/
-  https://de.wikipedia.org/wiki/Unternehmens-Identifikationsnummer
+More information:
+
+* https://www.uid.admin.ch/
+* https://de.wikipedia.org/wiki/Unternehmens-Identifikationsnummer
 
 >>> validate('CHE-100.155.212')
 'CHE100155212'
diff --git a/stdnum/ch/vat.py b/stdnum/ch/vat.py
index a61c49e..6e32ea7 100644
--- a/stdnum/ch/vat.py
+++ b/stdnum/ch/vat.py
@@ -28,9 +28,10 @@ ajoutée in French), "IVA" (Imposta sul valore aggiunto in 
Italian) or "TPV"
 This module only supports the "new" format that was introduced in 2011 which
 completely replaced the "old" 6-digit format in 2014.
 
-More information is available at:
-  
https://www.ch.ch/en/value-added-tax-number-und-business-identification-number/
-  https://www.uid.admin.ch/
+More information:
+
+* 
https://www.ch.ch/en/value-added-tax-number-und-business-identification-number/
+* https://www.uid.admin.ch/
 
 >>> validate('CHE-107.787.577 IVA')
 'CHE107787577IVA'
diff --git a/stdnum/cusip.py b/stdnum/cusip.py
index acd27d1..f685880 100644
--- a/stdnum/cusip.py
+++ b/stdnum/cusip.py
@@ -25,8 +25,9 @@ alphanumeric code where the first six characters identify the 
issuer,
 followed by two digits that identify and a check digit.
 
 More information:
-  https://en.wikipedia.org/wiki/CUSIP
-  https://www.cusip.com/
+
+* https://en.wikipedia.org/wiki/CUSIP
+* https://www.cusip.com/
 
 >>> validate('DUS0421C5')
 'DUS0421C5'
diff --git a/stdnum/dk/cpr.py b/stdnum/dk/cpr.py
index bdbbbb9..2566c64 100644
--- a/stdnum/dk/cpr.py
+++ b/stdnum/dk/cpr.py
@@ -31,9 +31,10 @@ checksum only for numbers that have a birth date before that 
because the
 numbers are also assigned to immigrants.
 
 More information:
-  https://en.wikipedia.org/wiki/Personal_identification_number_(Denmark)
-  https://da.wikipedia.org/wiki/CPR-nummer
-  https://cpr.dk/
+
+* https://en.wikipedia.org/wiki/Personal_identification_number_(Denmark)
+* https://da.wikipedia.org/wiki/CPR-nummer
+* https://cpr.dk/
 
 >>> validate('211062-5629')
 '2110625629'
diff --git a/stdnum/iban.py b/stdnum/iban.py
index ff33cdd..ae01a02 100644
--- a/stdnum/iban.py
+++ b/stdnum/iban.py
@@ -28,8 +28,9 @@ Some countries may also use checksum algorithms within their 
number but
 this is currently not checked by this number.
 
 More information:
-  https://en.wikipedia.org/wiki/International_Bank_Account_Number
-  
https://www.swift.com/products_services/bic_and_iban_format_registration_iban_format_r
+
+* https://en.wikipedia.org/wiki/International_Bank_Account_Number
+* 
https://www.swift.com/products_services/bic_and_iban_format_registration_iban_format_r
 
 >>> validate('GR16 0110 1050 0000 1054 7023 795')
 'GR1601101050000010547023795'
diff --git a/stdnum/imei.py b/stdnum/imei.py
index 8c0c1a0..f030071 100644
--- a/stdnum/imei.py
+++ b/stdnum/imei.py
@@ -25,7 +25,8 @@ check digit is included) or 16 digits (IMEISV) long. The 
check digit is
 validated using the Luhn algorithm.
 
 More information:
-  https://en.wikipedia.org/wiki/International_Mobile_Equipment_Identity
+
+* https://en.wikipedia.org/wiki/International_Mobile_Equipment_Identity
 
 >>> validate('35686800-004141-20')
 '3568680000414120'
diff --git a/stdnum/isbn.py b/stdnum/isbn.py
index 6b9233b..b511c4c 100644
--- a/stdnum/isbn.py
+++ b/stdnum/isbn.py
@@ -31,8 +31,9 @@ An ISBN has the following components:
 * a check digit
 
 More information:
-  https://en.wikipedia.org/wiki/International_Standard_Book_Number
-  https://www.isbn-international.org/range_file_generation
+
+* https://en.wikipedia.org/wiki/International_Standard_Book_Number
+* https://www.isbn-international.org/range_file_generation
 
 This module also offers functions for converting to ISBN-13 and formatting
 based on how the number should be split into a bookland code, group
diff --git a/stdnum/isil.py b/stdnum/isil.py
index 219e89e..30dea53 100644
--- a/stdnum/isil.py
+++ b/stdnum/isil.py
@@ -38,9 +38,10 @@ may be some validation possible with the second parts (some 
agencies provide
 web services for validation) but there is no common format to these services.
 
 More information:
-  https://en.wikipedia.org/wiki/ISBT_128
-  http://biblstandard.dk/isil/
-  http://www.iso.org/iso/catalogue_detail?csnumber=57332
+
+* https://en.wikipedia.org/wiki/ISBT_128
+* http://biblstandard.dk/isil/
+* http://www.iso.org/iso/catalogue_detail?csnumber=57332
 
 >>> validate('IT-RM0267')
 'IT-RM0267'
diff --git a/stdnum/isin.py b/stdnum/isin.py
index c6e93d5..135326a 100644
--- a/stdnum/isin.py
+++ b/stdnum/isin.py
@@ -28,7 +28,8 @@ This module does not currently separately validate the 
embedded national
 security identifier part (e.g. when it is a CUSIP).
 
 More information:
-  https://en.wikipedia.org/wiki/International_Securities_Identification_Number
+
+* https://en.wikipedia.org/wiki/International_Securities_Identification_Number
 
 >>> validate('US0378331005')
 'US0378331005'
diff --git a/stdnum/issn.py b/stdnum/issn.py
index 8be1f2c..4fa113d 100644
--- a/stdnum/issn.py
+++ b/stdnum/issn.py
@@ -27,8 +27,9 @@ hyphen. The last digit is a check digit and may be 0-9 or X 
(similar to
 ISBN-10).
 
 More information:
-  https://en.wikipedia.org/wiki/International_Standard_Serial_Number
-  http://www.issn.org/
+
+* https://en.wikipedia.org/wiki/International_Standard_Serial_Number
+* http://www.issn.org/
 
 >>> validate('0024-9319')
 '00249319'
diff --git a/stdnum/mx/rfc.py b/stdnum/mx/rfc.py
index 2e47238..10da251 100644
--- a/stdnum/mx/rfc.py
+++ b/stdnum/mx/rfc.py
@@ -35,12 +35,14 @@ in the number. However, it seems a lot of numbers 
(estimated at around 1.5%
 of all numbers) are in use with invalid check digits so this test is disabled
 by default.
 
-More information can be found at:
-  
http://www.sisi.org.mx/jspsi/documentos/2005/seguimiento/06101/0610100162005_065.doc
-  
https://es.wikipedia.org/wiki/Registro_Federal_de_Contribuyentes_(M%C3%A9xico)
+More information:
+
+* 
http://www.sisi.org.mx/jspsi/documentos/2005/seguimiento/06101/0610100162005_065.doc
+* 
https://es.wikipedia.org/wiki/Registro_Federal_de_Contribuyentes_(M%C3%A9xico)
 
 An online validation service is available at:
-  https://portalsat.plataforma.sat.gob.mx/ConsultaRFC/
+
+* https://portalsat.plataforma.sat.gob.mx/ConsultaRFC/
 
 >>> validate('GODE 561231 GR8')  # personal number
 'GODE561231GR8'
diff --git a/stdnum/nl/bsn.py b/stdnum/nl/bsn.py
index 280cc9b..c9e6f57 100644
--- a/stdnum/nl/bsn.py
+++ b/stdnum/nl/bsn.py
@@ -24,9 +24,10 @@ successor to the sofinummer. The number consists of up to 9 
digits (the
 leading 0's are commonly left out) and contains a simple checksum.
 
 More information:
-  https://en.wikipedia.org/wiki/National_identification_number#Netherlands
-  https://nl.wikipedia.org/wiki/Burgerservicenummer
-  http://www.burgerservicenummer.nl/
+
+* https://en.wikipedia.org/wiki/National_identification_number#Netherlands
+* https://nl.wikipedia.org/wiki/Burgerservicenummer
+* http://www.burgerservicenummer.nl/
 
 >>> validate('1112.22.333')
 '111222333'
@@ -56,7 +57,7 @@ def compact(number):
 
 def checksum(number):
     """Calculate the checksum over the number. A valid number should have
-    a check digit of 0."""
+    a checksum of 0."""
     return (sum((9 - i) * int(n) for i, n in enumerate(number[:-1])) -
             int(number[-1])) % 11
 
diff --git a/stdnum/nl/onderwijsnummer.py b/stdnum/nl/onderwijsnummer.py
index 0fbb3fc..b8d32c4 100644
--- a/stdnum/nl/onderwijsnummer.py
+++ b/stdnum/nl/onderwijsnummer.py
@@ -23,6 +23,10 @@ The onderwijsnummers (education number) is very similar to 
the BSN (Dutch
 national identification number) for students without a BSN. It uses a
 checksum mechanism similar to the BSN.
 
+More information:
+
+* https://nl.wikipedia.org/wiki/Onderwijsnummer
+
 >>> validate('1012.22.331')
 '101222331'
 >>> validate('100252333')
diff --git a/stdnum/pl/regon.py b/stdnum/pl/regon.py
index ac8cffb..82af03a 100644
--- a/stdnum/pl/regon.py
+++ b/stdnum/pl/regon.py
@@ -25,10 +25,11 @@ The REGON (Rejestr Gospodarki Narodowej) is a statistical 
identification
 number for businesses. National entities are assigned a 9-digit number, while
 local units append 5 digits to form a 14-digit number.
 
-More information can be found at:
-  http://bip.stat.gov.pl/en/regon/
-  http://www.stat.gov.pl/bip/regon_ENG_HTML.htm
-  https://wyszukiwarkaregon.stat.gov.pl/appBIR/index.aspx
+More information:
+
+* http://bip.stat.gov.pl/en/regon/
+* http://www.stat.gov.pl/bip/regon_ENG_HTML.htm
+* https://wyszukiwarkaregon.stat.gov.pl/appBIR/index.aspx
 
 >>> validate('192598184')
 '192598184'
diff --git a/stdnum/tr/tckimlik.py b/stdnum/tr/tckimlik.py
index a465cf3..4083229 100644
--- a/stdnum/tr/tckimlik.py
+++ b/stdnum/tr/tckimlik.py
@@ -24,9 +24,10 @@ The Turkish Identification Number (Türkiye Cumhuriyeti 
Kimlik Numarası) is a
 unique personal identification number assigned to every citizen of Turkey.
 The number consists of 11 digits and the last two digits are check digits.
 
-More information can be found at:
-  https://en.wikipedia.org/wiki/Turkish_Identification_Number
-  https://tckimlik.nvi.gov.tr/
+More information:
+
+* https://en.wikipedia.org/wiki/Turkish_Identification_Number
+* https://tckimlik.nvi.gov.tr/
 
 >>> validate('17291716060')
 '17291716060'
diff --git a/stdnum/us/ssn.py b/stdnum/us/ssn.py
index d4058bf..d08bd9a 100644
--- a/stdnum/us/ssn.py
+++ b/stdnum/us/ssn.py
@@ -35,9 +35,10 @@ number (e.g. name, date of birth, etc). Another means of 
validation is the
 Death Master File which can be ordered on DVD.
 
 More information:
-  https://en.wikipedia.org/wiki/Social_Security_number
-  https://www.ssa.gov/employer/verifySSN.htm
-  https://en.wikipedia.org/wiki/Death_Master_File
+
+* https://en.wikipedia.org/wiki/Social_Security_number
+* https://www.ssa.gov/employer/verifySSN.htm
+* https://en.wikipedia.org/wiki/Death_Master_File
 
 >>> validate('536-90-4399')
 '536904399'
diff --git a/stdnum/verhoeff.py b/stdnum/verhoeff.py
index 5d6fb15..02559d3 100644
--- a/stdnum/verhoeff.py
+++ b/stdnum/verhoeff.py
@@ -24,8 +24,9 @@ The Verhoeff algorithm is a checksum algorithm that should 
catch most common
 and multiplications and as a result is more complex than the Luhn algorithm.
 
 More information:
-  https://en.wikipedia.org/wiki/Verhoeff_algorithm
-  
https://en.wikibooks.org/wiki/Algorithm_Implementation/Checksums/Verhoeff_Algorithm
+
+* https://en.wikipedia.org/wiki/Verhoeff_algorithm
+* 
https://en.wikibooks.org/wiki/Algorithm_Implementation/Checksums/Verhoeff_Algorithm
 
 The module provides the checksum() function to calculate the Verhoeff
 checksum a calc_check_digit() function to generate a check digit that can be

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

Summary of changes:
 stdnum/ch/uid.py             |  7 +++---
 stdnum/ch/vat.py             |  7 +++---
 stdnum/cusip.py              |  5 ++--
 stdnum/dk/cpr.py             |  7 +++---
 stdnum/{imo.py => gb/nhs.py} | 58 ++++++++++++++++++++++----------------------
 stdnum/iban.py               |  5 ++--
 stdnum/imei.py               |  3 ++-
 stdnum/isbn.py               |  5 ++--
 stdnum/isil.py               |  7 +++---
 stdnum/isin.py               |  3 ++-
 stdnum/issn.py               |  5 ++--
 stdnum/mx/rfc.py             | 10 +++++---
 stdnum/nl/bsn.py             |  9 ++++---
 stdnum/nl/onderwijsnummer.py |  4 +++
 stdnum/numdb.py              |  4 +--
 stdnum/pl/regon.py           |  9 ++++---
 stdnum/tr/tckimlik.py        |  7 +++---
 stdnum/us/ssn.py             |  7 +++---
 stdnum/verhoeff.py           |  5 ++--
 19 files changed, 94 insertions(+), 73 deletions(-)
 copy stdnum/{imo.py => gb/nhs.py} (57%)


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/