lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.11-11-g6988d91

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

python-stdnum branch master updated. 1.11-11-g6988d91



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  6988d91a92c45d4a61ccc344a7761bbb8bd7c6ef (commit)
      from  82927799f0b9cc828eda671289dc7d760f2a6264 (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=6988d91a92c45d4a61ccc344a7761bbb8bd7c6ef

commit 6988d91a92c45d4a61ccc344a7761bbb8bd7c6ef
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Jun 2 15:21:30 2019 +0200

    Add Vergi Kimlik Numarası
    
    Closes https://github.com/arthurdejong/python-stdnum/issues/99

diff --git a/stdnum/tr/tckimlik.py b/stdnum/tr/tckimlik.py
index 0468d5f..e3dfcea 100644
--- a/stdnum/tr/tckimlik.py
+++ b/stdnum/tr/tckimlik.py
@@ -69,7 +69,7 @@ def calc_check_digits(number):
 
 
 def validate(number):
-    """Check if the number is a valid .C. Kimlik number. This checks the
+    """Check if the number is a valid T.C. Kimlik number. This checks the
     length and check digits."""
     number = compact(number)
     if not isdigits(number) or number[0] == '0':
@@ -82,7 +82,7 @@ def validate(number):
 
 
 def is_valid(number):
-    """Check if the number is a valid .C. Kimlik number."""
+    """Check if the number is a valid T.C. Kimlik number."""
     try:
         return bool(validate(number))
     except ValidationError:
diff --git a/stdnum/tr/vkn.py b/stdnum/tr/vkn.py
new file mode 100644
index 0000000..e23cb91
--- /dev/null
+++ b/stdnum/tr/vkn.py
@@ -0,0 +1,83 @@
+# vkn.py - functions for handling the Turkish tax identification number
+# coding: utf-8
+#
+# Copyright (C) 2019 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
+
+"""VKN (Vergi Kimlik Numarası, Turkish tax identification number).
+
+The Vergi Kimlik Numarası is the Turkish tax identification number used for
+businesses. The number consists of 10 digits where the first digit is derived
+from the company name.
+
+More information:
+
+* https://www.turkiye.gov.tr/gib-intvrg-vergi-kimlik-numarasi-dogrulama
+
+>>> validate('4540536920')
+'4540536920'
+>>> validate('4540536921')
+Traceback (most recent call last):
+    ...
+InvalidChecksum: ...
+>>> validate('454053692')
+Traceback (most recent call last):
+    ...
+InvalidLength: ...
+"""
+
+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()
+
+
+def calc_check_digit(number):
+    """Calculate the check digit for the specified number."""
+    s = 0
+    for i, n in enumerate(reversed(number[:9]), 1):
+        c1 = (int(n) + i) % 10
+        if c1:
+            c2 = (c1 * (2 ** i)) % 9 or 9
+            s += c2
+    return str((10 - s) % 10)
+
+
+def validate(number):
+    """Check if the number is a valid Vergi Kimlik Numarası. This checks the
+    length and check digits."""
+    number = compact(number)
+    if not isdigits(number):
+        raise InvalidFormat()
+    if len(number) != 10:
+        raise InvalidLength()
+    if calc_check_digit(number) != number[-1]:
+        raise InvalidChecksum()
+    return number
+
+
+def is_valid(number):
+    """Check if the number is a valid Vergi Kimlik Numarası. This checks the
+    length and check digits."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False
diff --git a/tests/test_tr_vkn.doctest b/tests/test_tr_vkn.doctest
new file mode 100644
index 0000000..99427dd
--- /dev/null
+++ b/tests/test_tr_vkn.doctest
@@ -0,0 +1,234 @@
+test_tr_vkn.doctest - more detailed doctests stdnum.tr.vkn
+
+Copyright (C) 2019 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.tr.vkn module.
+
+>>> from stdnum.tr import vkn
+>>> from stdnum.exceptions import *
+
+
+These have been found online and should all be valid numbers.
+
+>>> numbers = '''
+...
+... 0010213576
+... 0010441520
+... 0010448542
+... 0010526814
+... 0010715980
+... 0080463579
+... 0080527931
+... 0080545022
+... 0180044810
+... 0280352329
+... 0340251667
+... 0380372431
+... 0470075367
+... 0620203425
+... 0680581023
+... 0690039813
+... 0730335205
+... 0740002937
+... 0740369686
+... 0790015205
+... 0920235639
+... 0990287814
+... 0990379907
+... 0990382513
+... 0990382597
+... 1050060784
+... 1150621039
+... 1270153817
+... 1280263800
+... 1290088638
+... 1300312226
+... 1310481414
+... 1500417685
+... 1510326126
+... 1700226053
+... 1750058182
+... 1780528417
+... 1940338616
+... 1940429104
+... 2280560506
+... 2280737678
+... 2310378552
+... 2420384723
+... 2500315456
+... 2590326294
+... 2710531441
+... 2920458832
+... 2920601616
+... 3130285045
+... 3130406468
+... 3180394723
+... 3230937581
+... 3240021579
+... 3240032322
+... 3250423480
+... 3250498663
+... 3250536363
+... 3250536865
+... 3250560659
+... 3250561668
+... 3250563197
+... 3250564307
+... 3250580252
+... 3250591649
+... 3250592377
+... 3260264759
+... 3270052074
+... 3300554789
+... 3320090910
+... 3320414886
+... 3320419067
+... 3330047498
+... 3330191867
+... 3330514325
+... 3330670860
+... 3330738293
+... 3330784342
+... 3340346552
+... 3340512339
+... 3340521306
+... 3340522042
+... 3340532391
+... 3350427318
+... 3360098602
+... 3410209992
+... 3410224231
+... 3410262599
+... 3440302137
+... 3460048369
+... 3470145206
+... 3580294398
+... 3600179137
+... 3620269055
+... 3670040942
+... 3700035475
+... 3710206507
+... 3720054396
+... 3730264222
+... 3760112760
+... 3770333705
+... 3770335008
+... 3770347068
+... 3770407303
+... 3770440816
+... 3790331602
+... 3800363074
+... 3800387813
+... 3800459988
+... 3800548119
+... 3810421550
+... 3810435695
+... 3810463834
+... 3820141922
+... 3820216458
+... 3880430565
+... 3890039548
+... 3890382536
+... 3900499834
+... 4000209998
+... 4070322093
+... 4110245403
+... 4560329085
+... 4560337988
+... 4560340440
+... 4570274865
+... 4580413166
+... 4630340765
+... 4730259742
+... 4730262973
+... 4740097221
+... 4740288671
+... 4780392711
+... 4780393657
+... 4840500630
+... 4840507506
+... 4840515027
+... 4910300757
+... 4960273835
+... 5200337887
+... 5200397587
+... 5240377967
+... 5250033700
+... 5260407279
+... 5400299723
+... 5410386127
+... 5600419358
+... 5770389835
+... 5820358439
+... 6080300655
+... 6090213592
+... 6100274226
+... 6130847655
+... 6170213752
+... 6170305692
+... 6170380379
+... 6210184261
+... 6210288834
+... 6240292044
+... 6270283511
+... 6310391942
+... 6320201497
+... 6340308307
+... 6420017049
+... 6510412161
+... 6550254004
+... 6600296871
+... 6850437587
+... 7080351714
+... 7230309848
+... 7280054028
+... 7420306235
+... 7440382217
+... 7660381981
+... 7700021408
+... 7700294084
+... 7710094113
+... 7810147439
+... 7820457441
+... 7860191073
+... 8010405749
+... 8110348947
+... 8140161095
+... 8150130896
+... 8290246945
+... 8440247028
+... 8450208011
+... 8580348375
+... 8630017816
+... 8720064947
+... 8730268699
+... 8870198191
+... 9030505934
+... 9190297092
+... 9480321929
+... 9510380570
+... 9840234403
+... 9950395531
+... 9980588799
+... 9980697606
+... 9990112519
+...
+... '''
+>>> [x for x in numbers.splitlines() if x and not vkn.is_valid(x)]
+[]

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

Summary of changes:
 stdnum/tr/tckimlik.py           |   4 +-
 stdnum/{bg/pnf.py => tr/vkn.py} |  48 +++++----
 tests/test_tr_vkn.doctest       | 234 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 265 insertions(+), 21 deletions(-)
 copy stdnum/{bg/pnf.py => tr/vkn.py} (56%)
 create mode 100644 tests/test_tr_vkn.doctest


hooks/post-receive
-- 
python-stdnum