python-stdnum branch master updated. 1.3-7-ga1afa76
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum branch master updated. 1.3-7-ga1afa76
- From: Commits of the python-stdnum project <python-stdnum-commits [at] lists.arthurdejong.org>
- To: python-stdnum-commits [at] lists.arthurdejong.org
- Reply-to: python-stdnum-users [at] lists.arthurdejong.org
- Subject: python-stdnum branch master updated. 1.3-7-ga1afa76
- Date: Fri, 27 May 2016 23:29:51 +0200 (CEST)
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 a1afa76b39de86d76be947be07b846d44ea59ce9 (commit)
from 0a2f39e34e0ea19efc61ce5eb54e5c46012d858d (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=a1afa76b39de86d76be947be07b846d44ea59ce9
commit a1afa76b39de86d76be947be07b846d44ea59ce9
Author: Dimitri Papadopoulos <dimitri.papadopoulos@cea.fr>
Date: Sun May 22 19:39:18 2016 +0200
Add French NIR
Add module for NIR also known as social security number.
diff --git a/stdnum/fr/nir.py b/stdnum/fr/nir.py
new file mode 100644
index 0000000..bd9ce80
--- /dev/null
+++ b/stdnum/fr/nir.py
@@ -0,0 +1,80 @@
+# nir.py - functions for handling French NIR numbers
+#
+# Copyright (C) 2016 Dimitri Papadopoulos
+#
+# 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
+
+"""NIR (French personal identification number).
+
+The NIR (Numero d'Inscription au Repertoire national d'identification
+des personnes physiques) is a 15 digit number used to identify persons
+in France. All persons born in France are registered in the Repertoire
+national d'identification des personnes physiques (RNIPP) and assigned
+a NIR which consists of 15 digits where the two final digits are check
+digits. The NIR is used by French social security and is popularly known
+as the "social security number".
+
+More information:
+
+* http://www.insee.fr/en/methodes/default.asp?page=definitions/nir.htm
+
+>>> validate('2 95 10 99 126 111 93')
+'295109912611193'
+>>> validate('295109912611199') # invalid check digit
+Traceback (most recent call last):
+ ...
+InvalidChecksum: ...
+>>> format('295109912611193')
+'2 95 10 99 126 111 93'
+"""
+
+from stdnum.exceptions import *
+from stdnum.util import clean
+
+
+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 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) != 15:
+ raise InvalidLength()
+ if (97 - (int(number[:13]) % 97)) != int(number[13:]):
+ 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[:1], number[1:3], number[3:5], number[5:7],
+ number[7:10], number[10:13], number[13:]))
-----------------------------------------------------------------------
Summary of changes:
stdnum/{gb/nhs.py => fr/nir.py} | 49 ++++++++++++++++++-----------------------
1 file changed, 22 insertions(+), 27 deletions(-)
copy stdnum/{gb/nhs.py => fr/nir.py} (58%)
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/
- python-stdnum branch master updated. 1.3-7-ga1afa76,
Commits of the python-stdnum project