lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.14-7-g5082af4

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

python-stdnum branch master updated. 1.14-7-g5082af4



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  5082af48c037e51d51c1d920a1a8d1f0bbf7becb (commit)
      from  3a592e472ffd841dcb0c77488b77489fbe1eee99 (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=5082af48c037e51d51c1d920a1a8d1f0bbf7becb

commit 5082af48c037e51d51c1d920a1a8d1f0bbf7becb
Author: Matthias Schmid, M.Sc <ramsondon@gmail.com>
Date:   Tue Oct 27 09:04:30 2020 +0100

    Add Liechtenstein Personenidentifikationsnummer
    
    Closes https://github.com/arthurdejong/python-stdnum/pull/241
    Closes https://github.com/arthurdejong/python-stdnum/issues/125

diff --git a/stdnum/li/__init__.py b/stdnum/li/__init__.py
new file mode 100644
index 0000000..48d7291
--- /dev/null
+++ b/stdnum/li/__init__.py
@@ -0,0 +1,21 @@
+# __init__.py - collection of Liechtenstein numbers
+# coding: utf-8
+#
+# Copyright (C) 2020 Matthias Schmid
+#
+# 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 Liechtenstein numbers."""
diff --git a/stdnum/li/peid.py b/stdnum/li/peid.py
new file mode 100644
index 0000000..987db9f
--- /dev/null
+++ b/stdnum/li/peid.py
@@ -0,0 +1,68 @@
+# peid.py - library for Liechtenstein Personenidentifikationsnummer
+#
+# Copyright (C) 2020 Matthias Schmid
+#
+# 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
+
+"""PEID (Liechtenstein tax code for individuals and entities).
+
+The Personenidentifikationsnummer (PEID) is an numeric code up to 12 digits
+used to identify entities and individuals residing in Liechtenstein.
+
+More information:
+
+* https://www.oera.li/
+* 
https://www.oecd.org/tax/automatic-exchange/crs-implementation-and-assistance/tax-identification-numbers/LIECHTENSTEIN%20TIN.pdf
+
+>>> compact('00001234567')
+'1234567'
+>>> validate('1234567')  # personal number or entity number
+'1234567'
+>>> validate('00001234567')
+'1234567'
+>>> validate('00001234568913454545')
+Traceback (most recent call last):
+    ...
+InvalidLength: The number has an invalid length.
+"""
+
+from stdnum.exceptions import *
+from stdnum.util import clean, isdigits
+
+
+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().lstrip('0')
+
+
+def validate(number):
+    """Check if the given fiscal code is valid."""
+    number = compact(number)
+    if len(number) < 4 or len(number) > 12:
+        raise InvalidLength()
+    if not isdigits(number):
+        raise InvalidFormat()
+
+    return number
+
+
+def is_valid(number):
+    """Check if the given fiscal code is valid."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False
diff --git a/tests/test_li_peid.doctest b/tests/test_li_peid.doctest
new file mode 100644
index 0000000..3a30ac3
--- /dev/null
+++ b/tests/test_li_peid.doctest
@@ -0,0 +1,94 @@
+test_li_peid.doctest - more detailed doctests for stdnum.li.peid module
+
+Copyright (C) 2020 Matthias Schmid
+
+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
+
+
+This file contains more detailed doctests for the stdnum.li.peid module. It
+tries to test more corner cases and detailed functionality that is not really
+useful as module documentation.
+
+>>> from stdnum.li import peid
+
+
+Tests for some corner cases.
+
+>>> peid.validate('1339050')
+'1339050'
+>>> peid.validate('01339050')
+'1339050'
+>>> peid.validate('0001339050')
+'1339050'
+>>> peid.validate('0843089848')
+'843089848'
+
+>>> peid.validate('123')
+Traceback (most recent call last):
+    ...
+InvalidLength: The number has an invalid length.
+
+>>> peid.validate('1234567890123')
+Traceback (most recent call last):
+    ...
+InvalidLength: The number has an invalid length.
+
+>>> peid.validate('0001')
+Traceback (most recent call last):
+    ...
+InvalidLength: The number has an invalid length.
+
+>>> peid.validate('FF01339050')
+Traceback (most recent call last):
+    ...
+InvalidFormat: The number has an invalid format.
+
+>>> peid.validate('13-39050')
+Traceback (most recent call last):
+    ...
+InvalidFormat: The number has an invalid format.
+
+>>> peid.validate('568ABC91345')
+Traceback (most recent call last):
+    ...
+InvalidFormat: The number has an invalid format.
+
+
+These have been found online and should all be valid numbers.
+
+>>> numbers = '''
+...
+... 100364
+... 1053541
+... 2.580.073
+... 2031108
+... 2043832
+... 2385259
+... 2467526
+... 2518516
+... 2536979
+... 2547594
+... 2555984
+... 2557953
+... 2580190
+... 2581203
+... 2766
+... 84166
+... 84167
+...
+... '''
+>>> [x for x in numbers.splitlines() if x and not peid.is_valid(x)]
+[]

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

Summary of changes:
 stdnum/{ch => li}/__init__.py    |  6 +--
 stdnum/{ar/dni.py => li/peid.py} | 46 +++++++++-----------
 tests/test_li_peid.doctest       | 94 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+), 28 deletions(-)
 copy stdnum/{ch => li}/__init__.py (85%)
 copy stdnum/{ar/dni.py => li/peid.py} (59%)
 create mode 100644 tests/test_li_peid.doctest


hooks/post-receive
-- 
python-stdnum