lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.14-14-g126496c

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

python-stdnum branch master updated. 1.14-14-g126496c



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  126496c3824f70cb19c8bd489050e0dfd38926a1 (commit)
       via  b7b2af8a2d782bafb8e3a52479059b57243be026 (commit)
      from  0427b01985058cc01389b40df9f9bad61e547f9c (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=126496c3824f70cb19c8bd489050e0dfd38926a1

commit 126496c3824f70cb19c8bd489050e0dfd38926a1
Author: Leandro Regueiro <leandro.regueiro@gmail.com>
Date:   Sun Oct 25 18:14:26 2020 +0100

    Add support for Ukraine РНОКПП number
    
    Closes https://github.com/arthurdejong/python-stdnum/pull/242
    Closes https://github.com/arthurdejong/python-stdnum/issues/117

diff --git a/stdnum/ua/rntrc.py b/stdnum/ua/rntrc.py
new file mode 100644
index 0000000..301daa2
--- /dev/null
+++ b/stdnum/ua/rntrc.py
@@ -0,0 +1,87 @@
+# ubn.py - functions for handling Ukrainian RNTRC numbers
+# coding: utf-8
+#
+# Copyright (C) 2020 Leandro Regueiro
+#
+# 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
+
+"""РНОКПП, RNTRC (Individual taxpayer registration number in Ukraine).
+
+The РНОКПП (Реєстраційний номер облікової картки платника податків,
+registration number of the taxpayer's registration card) is a unique
+identification number that is provided to individuals within Ukraine. The
+number consists of 10 digits, the last being a check digit.
+
+More information:
+
+* https://uk.wikipedia.org/wiki/РНОКПП
+
+>>> validate('1759013776')
+'1759013776'
+>>> validate('1759013770')
+Traceback (most recent call last):
+    ...
+InvalidChecksum: ...
+>>> validate('12345')
+Traceback (most recent call last):
+    ...
+InvalidLength: ...
+>>> format(' 25 30 41 40 71 ')
+'2530414071'
+"""
+
+from stdnum.exceptions import *
+from stdnum.util import clean, isdigits
+
+
+def compact(number):
+    """Convert the number to the minimal representation."""
+    return clean(number, ' ').strip()
+
+
+def calc_check_digit(number):
+    """Calculate the check digit for number."""
+    weights = (-1, 5, 7, 9, 4, 6, 10, 5, 7)
+    total = sum(w * int(n) for w, n in zip(weights, number))
+    return str((total % 11) % 10)
+
+
+def validate(number):
+    """Check if the number is a valid Ukraine RNTRC (РНОКПП) number.
+
+    This checks the length, formatting and check digit.
+    """
+    number = compact(number)
+    if len(number) != 10:
+        raise InvalidLength()
+    if not isdigits(number):
+        raise InvalidFormat()
+    if number[-1] != calc_check_digit(number):
+        raise InvalidChecksum()
+    return number
+
+
+def is_valid(number):
+    """Check if the number is a valid Ukraine RNTRC (РНОКПП) number."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False
+
+
+def format(number):
+    """Reformat the number to the standard presentation format."""
+    return compact(number)
diff --git a/tests/test_ua_rntrc.doctest b/tests/test_ua_rntrc.doctest
new file mode 100644
index 0000000..638b313
--- /dev/null
+++ b/tests/test_ua_rntrc.doctest
@@ -0,0 +1,152 @@
+test_ua_rntrc.doctest - more detailed doctests for stdnum.ua.rntrc module
+
+Copyright (C) 2020 Leandro Regueiro
+
+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.ua.rntrc module. It
+tries to test more corner cases and detailed functionality that is not really
+useful as module documentation.
+
+>>> from stdnum.ua import rntrc
+
+
+Tests for some corner cases.
+
+>>> rntrc.validate('1759013776')
+'1759013776'
+>>> rntrc.format(' 25 30 41 40 71 ')
+'2530414071'
+>>> rntrc.validate('12345')
+Traceback (most recent call last):
+    ...
+InvalidLength: ...
+>>> rntrc.validate('VV59013776')
+Traceback (most recent call last):
+    ...
+InvalidFormat: ...
+>>> rntrc.validate('1759013770')
+Traceback (most recent call last):
+    ...
+InvalidChecksum: ...
+
+
+These have been found online and should all be valid numbers.
+
+>>> numbers = '''
+...
+... 1759013776
+... 1941106083
+... 2019304211
+... 2029212006
+... 2050823598
+... 2057604994
+... 2062412328
+... 2071907598
+... 2141715084
+... 2162316775
+... 2166209127
+... 2182917600
+... 2199602758
+... 2200300272
+... 2215911880
+... 2221604457
+... 2223820028
+... 2278520212
+... 2288012353
+... 2323000531
+... 2340714291
+... 2355207831
+... 2358623466
+... 2360711297
+... 2360803036
+... 2427616997
+... 2431516896
+... 2432915368
+... 2446410726
+... 2451902259
+... 2464921030
+... 2467920538
+... 2468920144
+... 2491109768
+... 2492601451
+... 2492810092
+... 2495912135
+... 25 30 41 40 71
+... 2507300273
+... 2511313590
+... 2511615015
+... 2514219625
+... 2517305837
+... 2518609656
+... 2521601845
+... 2522615927
+... 2525808071
+... 2526400856
+... 2531310373
+... 2537610987
+... 2548903136
+... 2595704439
+... 2618103132
+... 2656501477
+... 2661314935
+... 2668604464
+... 2687602513
+... 2715212635
+... 2722600497
+... 2725020233
+... 2735321158
+... 2756824294
+... 2756915742
+... 2767507288
+... 2777606331
+... 2796607557
+... 2803909085
+... 2849507907
+... 2862500663
+... 2881507890
+... 2886719190
+... 2940813715
+... 2976609691
+... 2979904457
+... 2981410717
+... 2986715322
+... 3022512606
+... 3039702911
+... 3047924216
+... 3065520146
+... 3072814835
+... 3087300101
+... 3099517368
+... 3104807458
+... 3104911417
+... 3121614071
+... 3124313135
+... 3130600734
+... 3132220152
+... 3152909256
+... 3171718420
+... 3190607860
+... 3215016793
+... 3279114362
+... 3323805078
+... 3366800663
+... 3451517675
+...
+... '''
+>>> [x for x in numbers.splitlines() if x and not rntrc.is_valid(x)]
+[]

https://arthurdejong.org/git/python-stdnum/commit/?id=b7b2af8a2d782bafb8e3a52479059b57243be026

commit b7b2af8a2d782bafb8e3a52479059b57243be026
Author: Leandro Regueiro <leandro.regueiro@gmail.com>
Date:   Sun Oct 25 15:18:57 2020 +0100

    Add support for Ukraine ЄДРПОУ number
    
    Closes https://github.com/arthurdejong/python-stdnum/pull/242
    Closes https://github.com/arthurdejong/python-stdnum/issues/117

diff --git a/stdnum/ua/__init__.py b/stdnum/ua/__init__.py
new file mode 100644
index 0000000..1838c52
--- /dev/null
+++ b/stdnum/ua/__init__.py
@@ -0,0 +1,21 @@
+# __init__.py - collection of Ukrainian numbers
+# coding: utf-8
+#
+# Copyright (C) 2020 Leandro Regueiro
+#
+# 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 Ukrainian numbers."""
diff --git a/stdnum/ua/edrpou.py b/stdnum/ua/edrpou.py
new file mode 100644
index 0000000..fc40497
--- /dev/null
+++ b/stdnum/ua/edrpou.py
@@ -0,0 +1,95 @@
+# ubn.py - functions for handling Ukrainian EDRPOU numbers
+# coding: utf-8
+#
+# Copyright (C) 2020 Leandro Regueiro
+#
+# 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
+
+"""ЄДРПОУ, EDRPOU (Identifier for enterprises and organizations in Ukraine).
+
+The ЄДРПОУ (Єдиного державного реєстру підприємств та організацій України,
+Unified State Register of Enterprises and Organizations of Ukraine) is a
+unique identification number of a legal entities in Ukraine. Th number
+consists of 8 digits, the last being a check digit.
+
+More information:
+
+* https://uk.wikipedia.org/wiki/Код_ЄДРПОУ
+* http://1cinfo.com.ua/Articles/Proverka_koda_po_EDRPOU.aspx
+
+>>> validate('32855961')
+'32855961'
+>>> validate('32855968')
+Traceback (most recent call last):
+    ...
+InvalidChecksum: ...
+>>> validate('12345')
+Traceback (most recent call last):
+    ...
+InvalidLength: ...
+>>> format(' 32855961 ')
+'32855961'
+"""
+
+from stdnum.exceptions import *
+from stdnum.util import clean, isdigits
+
+
+def compact(number):
+    """Convert the number to the minimal representation."""
+    return clean(number, ' ').strip()
+
+
+def calc_check_digit(number):
+    """Calculate the check digit for number."""
+    weights = (1, 2, 3, 4, 5, 6, 7)
+    if number[0] in '345':
+        weights = (7, 1, 2, 3, 4, 5, 6)
+    total = sum(w * int(n) for w, n in zip(weights, number))
+    if total % 11 < 10:
+        return str(total % 11)
+    # Calculate again with other weights
+    weights = tuple(w + 2 for w in weights)
+    total = sum(w * int(n) for w, n in zip(weights, number))
+    return str(total % 11)
+
+
+def validate(number):
+    """Check if the number is a valid Ukraine EDRPOU (ЄДРПОУ) number.
+
+    This checks the length, formatting and check digit.
+    """
+    number = compact(number)
+    if len(number) != 8:
+        raise InvalidLength()
+    if not isdigits(number):
+        raise InvalidFormat()
+    if number[-1] != calc_check_digit(number):
+        raise InvalidChecksum()
+    return number
+
+
+def is_valid(number):
+    """Check if the number is a valid Ukraine EDRPOU (ЄДРПОУ) number."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False
+
+
+def format(number):
+    """Reformat the number to the standard presentation format."""
+    return compact(number)
diff --git a/tests/test_ua_edrpou.doctest b/tests/test_ua_edrpou.doctest
new file mode 100644
index 0000000..32bb979
--- /dev/null
+++ b/tests/test_ua_edrpou.doctest
@@ -0,0 +1,304 @@
+test_ua_edrpou.doctest - more detailed doctests for stdnum.ua.edrpou module
+
+Copyright (C) 2020 Leandro Regueiro
+
+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.ua.edrpou module. It
+tries to test more corner cases and detailed functionality that is not really
+useful as module documentation.
+
+>>> from stdnum.ua import edrpou
+
+
+Tests for some corner cases.
+
+>>> edrpou.validate('32855961')
+'32855961'
+>>> edrpou.format('32855961')
+'32855961'
+>>> edrpou.validate('12345')
+Traceback (most recent call last):
+    ...
+InvalidLength: ...
+>>> edrpou.validate('VV855961')
+Traceback (most recent call last):
+    ...
+InvalidFormat: ...
+>>> edrpou.validate('32855968')
+Traceback (most recent call last):
+    ...
+InvalidChecksum: ...
+
+
+These have been found online and should all be valid numbers.
+
+>>> numbers = '''
+...
+... 00022438
+... 00022496
+... 00022504
+... 00022585
+... 00022651
+... 00022680
+... 00032945
+... 00034022
+... 00034051
+... 00100227
+... 00130694
+... 00130725
+... 00130926
+... 00131564
+... 00131587
+... 00131819
+... 00131954
+... 00132003
+... 00217857
+... 00231610
+... 00260652
+... 00282406
+... 00282435
+... 00290280
+... 00308778
+... 00372109
+... 00443074
+... 00480247
+... 00493706
+... 00497006
+... 00659101
+... 00692009
+... 00740599
+... 00849184
+... 01056273
+... 01072609
+... 01192220
+... 01415559
+... 01497439
+... 01566117
+... 01566330
+... 01881876
+... 01984613
+... 01986380
+... 01991116
+... 01996272
+... 02010669
+... 02010758
+... 02010830
+... 02011261
+... 02066769
+... 02070766
+... 02070812
+... 02070950
+... 02070987
+... 02125102
+... 02125237
+... 02125266
+... 02136554
+... 02139133
+... 02139771
+... 02142448
+... 02145010
+... 02147606
+... 02224548
+... 02363072
+... 02426097
+... 02573817
+... 02909938
+... 02909996
+... 02910031
+... 02910060
+... 02910108
+... 03114017
+... 03293304
+... 03338030
+... 03346822
+... 03355353
+... 03356128
+... 03356571
+... 03359658
+... 03361661
+... 03361678
+... 03361780
+... 03491079
+... 03491085
+... 03491180
+... 03491300
+... 03491406
+... 03491435
+... 03499945
+... 04013755
+... 04014246
+... 04059243
+... 04350665
+... 04375151
+... 04824652
+... 05379487
+... 05387179
+... 05396638
+... 05460344
+... 05465672
+... 05489555
+... 05786100
+... 07904041
+... 08027576
+... 08183359
+... 08563808
+... 08564794
+... 08571363
+... 08803543
+... 13857564
+... 13915014
+... 13956473
+... 13986712
+... 14038383
+... 14282338
+... 14282829
+... 14307481
+... 14307529
+... 14310299
+... 14352406
+... 19350062
+... 20001303
+... 20001585
+... 20001591
+... 20001823
+... 20003749
+... 20022334
+... 20077720
+... 20442705
+... 20488297
+... 20551088
+... 21045573
+... 21705897
+... 21726250
+... 22518134
+... 22530614
+... 22800735
+... 22815333
+... 23226362
+... 23293513
+... 23505151
+... 23541342
+... 23935584
+... 24283333
+... 24976272
+... 24978555
+... 25042882
+... 25836018
+... 26112972
+... 26255795
+... 26510514
+... 26615223
+... 30327425
+... 30638956
+... 30674235
+... 30702701
+... 30998764
+... 31394728
+... 31584378
+... 31725604
+... 31850889
+... 31867274
+... 32000106
+... 32161160
+... 32277963
+... 32355213
+... 32359108
+... 32523934
+... 32610639
+... 32737851
+... 32855961
+... 33124015
+... 33499803
+... 34201058
+... 34275671
+... 34334305
+... 34827358
+... 34837504
+... 34868595
+... 35264255
+... 35622956
+... 35623077
+... 36041214
+... 36177661
+... 36297353
+... 36383349
+... 36521731
+... 36598008
+... 37107050
+... 37181129
+... 37199618
+... 37324614
+... 37451388
+... 37508470
+... 37533381
+... 37567646
+... 37609984
+... 37819430
+... 37951998
+... 37958419
+... 37988155
+... 38004897
+... 38066005
+... 38149966
+... 38168926
+... 38203737
+... 38243641
+... 38337116
+... 38516938
+... 38572374
+... 38775688
+... 39034697
+... 39292197
+... 39308149
+... 39393260
+... 39434500
+... 39592941
+... 39736985
+... 39738364
+... 39816845
+... 39896543
+... 40046124
+... 40081200
+... 40081221
+... 40081237
+... 40108625
+... 40108866
+... 40109173
+... 41399586
+... 41436842
+... 41475043
+... 41617928
+... 41800368
+... 41810109
+... 42258617
+... 42262749
+... 42309535
+... 42485471
+... 42588390
+... 42598807
+... 43178370
+... 43476227
+... 43518172
+... 43529818
+... 43586656
+... 43618792
+... 43629317
+...
+... '''
+>>> [x for x in numbers.splitlines() if x and not edrpou.is_valid(x)]
+[]

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

Summary of changes:
 stdnum/{ch => ua}/__init__.py      |   6 +-
 stdnum/{tw/ubn.py => ua/edrpou.py} |  58 +++----
 stdnum/{tw/ubn.py => ua/rntrc.py}  |  52 +++----
 tests/test_ua_edrpou.doctest       | 304 +++++++++++++++++++++++++++++++++++++
 tests/test_ua_rntrc.doctest        | 152 +++++++++++++++++++
 5 files changed, 512 insertions(+), 60 deletions(-)
 copy stdnum/{ch => ua}/__init__.py (85%)
 copy stdnum/{tw/ubn.py => ua/edrpou.py} (52%)
 copy stdnum/{tw/ubn.py => ua/rntrc.py} (55%)
 create mode 100644 tests/test_ua_edrpou.doctest
 create mode 100644 tests/test_ua_rntrc.doctest


hooks/post-receive
-- 
python-stdnum