lists.arthurdejong.org
RSS feed

python-stdnum commit: r95 - in python-stdnum: . stdnum stdnum/nl tests

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

python-stdnum commit: r95 - in python-stdnum: . stdnum stdnum/nl tests



Author: arthur
Date: Thu Feb  2 22:09:26 2012
New Revision: 95
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=95&view=revision

Log:
add an onderwijsnummer (Dutch school number) module

Added:
   python-stdnum/stdnum/nl/onderwijsnummer.py
Modified:
   python-stdnum/README
   python-stdnum/stdnum/__init__.py
   python-stdnum/stdnum/nl/bsn.py
   python-stdnum/tests/test_robustness.doctest

Modified: python-stdnum/README
==============================================================================
--- python-stdnum/README        Sat Dec 31 17:16:51 2011        (r94)
+++ python-stdnum/README        Thu Feb  2 22:09:26 2012        (r95)
@@ -15,6 +15,7 @@
  * ISAN (International Standard Audiovisual Number)
  * EAN (International Article Number)
  * BSN (Burgerservicenummer, the Dutch national identification number)
+ * Onderwijsnummer (Dutch school number)
  * CPF (Cadastro de Pessoas Físicas, the Brazillian national identification
    number)
  * SSN (U.S. Social Security Number)
@@ -65,7 +66,7 @@
 Copyright
 ---------
 
-Copyright (C) 2010, 2011 Arthur de Jong
+Copyright (C) 2010, 2011, 2012 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

Modified: python-stdnum/stdnum/__init__.py
==============================================================================
--- python-stdnum/stdnum/__init__.py    Sat Dec 31 17:16:51 2011        (r94)
+++ python-stdnum/stdnum/__init__.py    Thu Feb  2 22:09:26 2012        (r95)
@@ -1,7 +1,7 @@
 # __init__.py - main module
 # coding: utf-8
 #
-# Copyright (C) 2010, 2011 Arthur de Jong
+# Copyright (C) 2010, 2011, 2012 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
@@ -29,6 +29,7 @@
  * ISAN (International Standard Audiovisual Number)
  * EAN (International Article Number)
  * BSN (Burgerservicenummer, the Dutch national identification number)
+ * Onderwijsnummer (Dutch school number)
  * CPF (Cadastro de Pessoas Físicas, the Brazillian national identification
    number)
  * SSN (U.S. Social Security Number)

Modified: python-stdnum/stdnum/nl/bsn.py
==============================================================================
--- python-stdnum/stdnum/nl/bsn.py      Sat Dec 31 17:16:51 2011        (r94)
+++ python-stdnum/stdnum/nl/bsn.py      Thu Feb  2 22:09:26 2012        (r95)
@@ -1,6 +1,6 @@
 # bsn.py - functions for handling BSNs
 #
-# Copyright (C) 2010, 2011 Arthur de Jong
+# Copyright (C) 2010, 2011, 2012 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
@@ -39,9 +39,10 @@
     return (9 - len(number)) * '0' + number
 
 
-def _calc_checksum(number):
+def calc_checksum(number):
     """Calculate the checksum over the number."""
-    return sum((9 - i) * int(number[i]) for i in range(8)) - int(number[8])
+    return (sum((9 - i) * int(number[i]) for i in range(8)) -
+            int(number[8])) % 11
 
 
 def is_valid(number):
@@ -54,7 +55,7 @@
     return len(number) == 9 and \
            number.isdigit() and \
            int(number) > 0 and \
-           _calc_checksum(number) % 11 == 0
+           calc_checksum(number) == 0
 
 
 def format(number):

Added: python-stdnum/stdnum/nl/onderwijsnummer.py
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ python-stdnum/stdnum/nl/onderwijsnummer.py  Thu Feb  2 22:09:26 2012        
(r95)
@@ -0,0 +1,46 @@
+# onderwijsnummer.py - functions for handling onderwijsnummers
+#
+# Copyright (C) 2012 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
+
+"""Module for handling onderwijsnummers (school number), very similar to the 
BSN
+(Dutch national identification number) but for students without a BSN.
+
+>>> is_valid('101222331')
+True
+>>> is_valid('100252333')
+False
+>>> compact('1234.56.782')
+'123456782'
+"""
+
+from stdnum.nl.bsn import compact, calc_checksum
+
+
+def is_valid(number):
+    """Checks to see if the number provided is a valid onderwijsnummer.
+    This checks the length and whether the check digit is correct and
+    whether it starts with the right sequence."""
+    try:
+        number = compact(number)
+    except:
+        return False
+    return len(number) == 9 and \
+           number.isdigit() and \
+           int(number) > 0 and \
+           calc_checksum(number) == 5 and \
+           number.startswith('10')

Modified: python-stdnum/tests/test_robustness.doctest
==============================================================================
--- python-stdnum/tests/test_robustness.doctest Sat Dec 31 17:16:51 2011        
(r94)
+++ python-stdnum/tests/test_robustness.doctest Thu Feb  2 22:09:26 2012        
(r95)
@@ -1,6 +1,6 @@
 test_robustness.doctest - test is_valid() fcuntions to not break
 
-Copyright (C) 2011 Arthur de Jong
+Copyright (C) 2011, 2012 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
@@ -27,7 +27,7 @@
 >>> from stdnum import grid, iban, imei, imsi, isan, isbn, isil, ismn, issn, 
 >>> ean
 >>> from stdnum import luhn, meid, verhoeff
 >>> from stdnum.iso7064 import mod_11_10, mod_11_2, mod_37_2, mod_37_36, 
 >>> mod_97_10
->>> from stdnum.nl import bsn
+>>> from stdnum.nl import bsn, onderwijsnummer
 >>> from stdnum.br import cpf
 >>> from stdnum.us import ssn
 >>> from stdnum.fi import hetu
-- 
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits/