lists.arthurdejong.org
RSS feed

python-stdnum commit: r102 - in python-stdnum: . stdnum stdnum/fr tests

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

python-stdnum commit: r102 - in python-stdnum: . stdnum stdnum/fr tests



Author: arthur
Date: Sun Feb  5 22:12:18 2012
New Revision: 102
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=102&view=revision

Log:
add a SIREN (Système d'Identification du Répertoire des Entreprises, a French 
company identification number) module

Added:
   python-stdnum/stdnum/fr/
   python-stdnum/stdnum/fr/__init__.py
   python-stdnum/stdnum/fr/siren.py
Modified:
   python-stdnum/README
   python-stdnum/stdnum/__init__.py
   python-stdnum/tests/test_robustness.doctest

Modified: python-stdnum/README
==============================================================================
--- python-stdnum/README        Sun Feb  5 21:51:19 2012        (r101)
+++ python-stdnum/README        Sun Feb  5 22:12:18 2012        (r102)
@@ -20,6 +20,8 @@
  * CPF (Cadastro de Pessoas Físicas, the Brazillian national identification
    number)
  * RČ (Rodné číslo, the Czech birth numbers)
+ * SIREN (Système d'Identification du Répertoire des Entreprises, a French
+   company identification number)
  * SSN (U.S. Social Security Number)
  * HETU (Finnish personal identity code)
  * IMEI (International Mobile Equipment Identity)

Modified: python-stdnum/stdnum/__init__.py
==============================================================================
--- python-stdnum/stdnum/__init__.py    Sun Feb  5 21:51:19 2012        (r101)
+++ python-stdnum/stdnum/__init__.py    Sun Feb  5 22:12:18 2012        (r102)
@@ -34,6 +34,8 @@
  * CPF (Cadastro de Pessoas Físicas, the Brazillian national identification
    number)
  * RČ (Rodné číslo, the Czech birth numbers)
+ * SIREN (Système d'Identification du Répertoire des Entreprises, a French
+   company identification number)
  * SSN (U.S. Social Security Number)
  * HETU (Finnish personal identity code)
  * IMEI (International Mobile Equipment Identity)

Added: python-stdnum/stdnum/fr/__init__.py
==============================================================================

Added: python-stdnum/stdnum/fr/siren.py
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ python-stdnum/stdnum/fr/siren.py    Sun Feb  5 22:12:18 2012        (r102)
@@ -0,0 +1,49 @@
+# siren.py - functions for handling French SIREN numbers
+# coding: utf-8
+#
+# 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 French SIREN (Système d’Identification du
+Répertoire des Entreprises) numbers, used to identify French companies.
+
+>>> compact('552 008 443')
+'552008443'
+>>> is_valid('404833048')
+True
+>>> is_valid('404833047')
+False
+"""
+
+from stdnum.util import clean
+from stdnum import luhn
+
+
+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 is_valid(number):
+    """Checks to see if the number provided is a valid number. This checks
+    the length, formatting and check digit."""
+    try:
+        number = compact(number)
+    except:
+        return False
+    return len(number) == 9 and number.isdigit() and luhn.is_valid(number)

Modified: python-stdnum/tests/test_robustness.doctest
==============================================================================
--- python-stdnum/tests/test_robustness.doctest Sun Feb  5 21:51:19 2012        
(r101)
+++ python-stdnum/tests/test_robustness.doctest Sun Feb  5 22:12:18 2012        
(r102)
@@ -29,6 +29,7 @@
 >>> from stdnum.br import cpf
 >>> from stdnum.cz import rc
 >>> from stdnum.fi import hetu
+>>> from stdnum.fr import siren
 >>> from stdnum.iso7064 import mod_11_10, mod_11_2, mod_37_2, mod_37_36, 
 >>> mod_97_10
 >>> from stdnum.nl import bsn, onderwijsnummer, btw
 >>> from stdnum.us import ssn
-- 
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits/