lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.6-17-gd24a439

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

python-stdnum branch master updated. 1.6-17-gd24a439



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  d24a439d2a7c5ce3ed1628e3393f67cae45b67e2 (commit)
      from  53cc0dca1a3a5a7f4d543c5527c70cddfdf9f32b (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=d24a439d2a7c5ce3ed1628e3393f67cae45b67e2

commit d24a439d2a7c5ce3ed1628e3393f67cae45b67e2
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Mon Sep 4 21:37:58 2017 +0200

    Add Estonian Registrikood
    
    This is based on what was done by Mohammed Salman of Holvi. This adds
    more tests and validates the check digit.
    
    This uses the check digit algorithm from Isikukood which seems to work
    with all tested numbers although there is no confirmation that this is
    the correct algorithm.

diff --git a/stdnum/ee/registrikood.py b/stdnum/ee/registrikood.py
new file mode 100644
index 0000000..778fb9b
--- /dev/null
+++ b/stdnum/ee/registrikood.py
@@ -0,0 +1,84 @@
+# registrikood.py - functions for handling the Estonian Registrikood
+# coding: utf-8
+#
+# Copyright (C) 2017 Holvi Payment Services
+# Copyright (C) 2017 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
+
+"""Registrikood (Estonian organisation registration code).
+
+All organisations are assigned a unique tax identification code from the
+commercial register, from the state register or from the non-profit
+associations and foundations register. The code consists of 8 digits.
+
+Commercial company numbers start with a 1, schools and government numbers
+with a 7, non-profit organisations with an 8 and foundations with a 9. The
+number uses the same check digit algorithm as the Isikukood although that
+fact is undocumented.
+
+More information:
+
+* https://ariregister.rik.ee/
+* https://mtr.mkm.ee/
+
+>>> validate('12345678')
+'12345678'
+>>> validate('12345679')
+Traceback (most recent call last):
+    ...
+InvalidChecksum: ...
+>>> validate('32345674')
+Traceback (most recent call last):
+    ...
+InvalidComponent: ...
+"""
+
+from stdnum.exceptions import *
+from stdnum.util import clean
+from stdnum.ee.ik import calc_check_digit
+
+
+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 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) != 8:
+        raise InvalidLength()
+    if number[0] not in '1789':
+        raise InvalidComponent()
+    if number[-1] != calc_check_digit(number):
+        raise InvalidChecksum()
+    return number
+
+
+def is_valid(number):
+    """
+    Checks if the number provided is valid. This checks the length,
+    and check digit.
+    """
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False
diff --git a/tests/test_ee_registrikood.doctest 
b/tests/test_ee_registrikood.doctest
new file mode 100644
index 0000000..1ed4440
--- /dev/null
+++ b/tests/test_ee_registrikood.doctest
@@ -0,0 +1,148 @@
+test_ee_registrikood.doctest - more detailed doctests for 
stdnum.ee.registrikood module
+
+Copyright (C) 2017 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
+
+
+This file contains more detailed doctests for the stdnum.ee.registrikood. It
+tries to cover more corner cases and detailed functionality that is not
+really useful as module documentation.
+
+>>> from stdnum.ee import registrikood
+>>> from stdnum.exceptions import *
+
+
+Some simple tests for corner cases:
+
+>>> registrikood.validate('123456789')
+Traceback (most recent call last):
+    ...
+InvalidLength: ...
+>>> registrikood.validate('1234567A')
+Traceback (most recent call last):
+    ...
+InvalidFormat: ...
+
+
+These have been found online and should all be valid numbers.
+
+>>> numbers = """
+...
+... 10000024
+... 10000030
+... 10000047
+... 10000171
+... 10254782
+... 10324169
+... 10491045
+... 10591640
+... 10722527
+... 10732046
+... 10953764
+... 11041309
+... 11104323
+... 11126796
+... 11129553
+... 11405303
+... 11426771
+... 11456861
+... 11521759
+... 11559868
+... 11664625
+... 11910691
+... 11984324
+... 12073932
+... 12111472
+... 12202654
+... 12493640
+... 70000823
+... 70002420
+... 70004264
+... 70005542
+... 75000561
+... 75000667
+... 75002287
+... 75002884
+... 75005334
+... 75005392
+... 75005618
+... 75006820
+... 75007267
+... 75008769
+... 75010476
+... 75012952
+... 75015580
+... 75016177
+... 75016993
+... 75017857
+... 75018325
+... 75018495
+... 75018822
+... 75020670
+... 75021043
+... 75021304
+... 75021617
+... 75024018
+... 75024509
+... 75024567
+... 75025153
+... 75025762
+... 75026968
+... 75027494
+... 75033069
+... 80026261
+... 80033947
+... 80040433
+... 80041421
+... 80046097
+... 80052459
+... 80078915
+... 80079820
+... 80093530
+... 80095629
+... 80107858
+... 80112196
+... 80132454
+... 80173430
+... 80186390
+... 80196158
+... 80213520
+... 80234120
+... 80287895
+... 80291371
+... 80293625
+... 80302784
+... 80309332
+... 80314929
+... 80319075
+... 80336642
+... 90004740
+... 90004817
+... 90006006
+... 90006549
+... 90006822
+... 90006845
+... 90007247
+... 90007796
+... 90008287
+... 90009370
+... 90010671
+... 90010887
+...
+... """
+>>> [x for x in numbers.splitlines() if x and not registrikood.is_valid(x)]
+[]

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

Summary of changes:
 stdnum/{eu/eic.py => ee/registrikood.py} |  62 ++++++-------
 tests/test_ee_registrikood.doctest       | 148 +++++++++++++++++++++++++++++++
 2 files changed, 177 insertions(+), 33 deletions(-)
 copy stdnum/{eu/eic.py => ee/registrikood.py} (53%)
 create mode 100644 tests/test_ee_registrikood.doctest


hooks/post-receive
-- 
python-stdnum
-- 
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
https://lists.arthurdejong.org/python-stdnum-commits/