lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.13-25-g356a729

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

python-stdnum branch master updated. 1.13-25-g356a729



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  356a729bf31ad8e971f3049523ddf4498dd999ca (commit)
      from  e49e0e9e213b36b4debfcefbf1edcfdb554432ea (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=356a729bf31ad8e971f3049523ddf4498dd999ca

commit 356a729bf31ad8e971f3049523ddf4498dd999ca
Author: Leandro Regueiro <leandro.regueiro@gmail.com>
Date:   Tue Mar 31 22:15:35 2020 +0200

    Add Israeli TIN number
    
    Closes https://github.com/arthurdejong/python-stdnum/pull/208
    Closes https://github.com/arthurdejong/python-stdnum/issues/107

diff --git a/stdnum/il/__init__.py b/stdnum/il/__init__.py
index 91a474e..b002751 100644
--- a/stdnum/il/__init__.py
+++ b/stdnum/il/__init__.py
@@ -19,3 +19,6 @@
 # 02110-1301 USA
 
 """Collection of Israeli numbers."""
+
+# provide aliases
+from stdnum.il import hp as vat  # noqa: F401
diff --git a/stdnum/il/hp.py b/stdnum/il/hp.py
new file mode 100644
index 0000000..28386c5
--- /dev/null
+++ b/stdnum/il/hp.py
@@ -0,0 +1,87 @@
+# hp.py - functions for handling Israeli company 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
+
+"""Company Number (מספר חברה, or short ח.פ. Israeli company number).
+
+It consists of nine digits and includes a check digit. For companies
+the first digit is a 5. The first two digits identify the type of
+company.
+
+More information:
+
+* https://he.wikipedia.org/wiki/תאגיד#מספר_רישום_התאגיד
+* 
https://www.oecd.org/tax/automatic-exchange/crs-implementation-and-assistance/tax-identification-numbers/Israel-TIN.pdf
+* https://wiki.scn.sap.com/wiki/display/CRM/Israel
+
+>>> validate('516179157')
+'516179157'
+>>> format(' 5161 79157 ')
+'516179157'
+>>> validate('516179150')  # invalid check digit
+Traceback (most recent call last):
+    ...
+InvalidChecksum: ...
+>>> validate('490154203237518')  # longer than 9 digits
+Traceback (most recent call last):
+    ...
+InvalidLength: ...
+>>> validate('416179157')
+Traceback (most recent call last):
+    ...
+InvalidComponent: ...
+"""
+
+from stdnum import luhn
+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 separators and removes surrounding whitespace."""
+    return clean(number, ' -').strip()
+
+
+def validate(number):
+    """Check if the number provided is a valid ID. This checks the length,
+    formatting and check digit."""
+    number = compact(number)
+    if len(number) != 9:
+        raise InvalidLength()
+    if not isdigits(number) or int(number) <= 0:
+        raise InvalidFormat()
+    if number[0] != '5':
+        raise InvalidComponent()
+    luhn.validate(number)
+    return number
+
+
+def is_valid(number):
+    """Check if the number provided is a valid ID. This checks the length,
+    formatting and check digit."""
+    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_il_hp.doctest b/tests/test_il_hp.doctest
new file mode 100644
index 0000000..baaecc3
--- /dev/null
+++ b/tests/test_il_hp.doctest
@@ -0,0 +1,257 @@
+test_il_hp.doctest - more detailed doctests for stdnum.il.hp 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.il.hp module. It
+tries to test more corner cases and detailed functionality that is not really
+useful as module documentation.
+
+>>> from stdnum.il import hp
+
+
+Basic tests
+
+>>> hp.validate('516179157')
+'516179157'
+>>> hp.validate('1234')
+Traceback (most recent call last):
+  ...
+InvalidLength: ...
+>>> hp.validate('516179XXX')
+Traceback (most recent call last):
+  ...
+InvalidFormat: ...
+>>> hp.validate('416179157')
+Traceback (most recent call last):
+  ...
+InvalidComponent: ...
+>>> hp.validate('516179150')
+Traceback (most recent call last):
+  ...
+InvalidChecksum: ...
+>>> hp.format(' 5161 79157 ')
+'516179157'
+
+
+>>> numbers = '''
+...
+... 500107420
+... 500261359
+... 510361371
+... 510771314
+... 510790256
+... 510923402
+... 510952328
+... 510976103
+... 511100554
+... 511193815
+... 511216129
+... 511221947
+... 511237018
+... 511240350
+... 511610966
+... 511622375
+... 511770281
+... 511772840
+... 511773897
+... 511895286
+... 511930828
+... 512053521
+... 512053968
+... 512131228
+... 512244245
+... 512440934
+... 512476789
+... 512506643
+... 512516014
+... 512629254
+... 512662628
+... 512708074
+... 512708363
+... 512740861
+... 512749532
+... 512802174
+... 512872359
+... 512899667
+... 512946948
+... 512947276
+... 512951526
+... 512962010
+... 512976028
+... 513070623
+... 513079582
+... 513107334
+... 513174813
+... 513302588
+... 513374355
+... 513403857
+... 513444224
+... 513466532
+... 513544833
+... 513565473
+... 513606582
+... 513688481
+... 513701169
+... 513704999
+... 513724187
+... 513771519
+... 513795948
+... 513797027
+... 513853085
+... 513879205
+... 513906420
+... 514078138
+... 514125798
+... 514174341
+... 514240761
+... 514295062
+... 514306844
+... 514307107
+... 514350024
+... 514462282
+... 514471127
+... 514486182
+... 514513357
+... 514521996
+... 514536648
+... 514563469
+... 514607290
+... 514643519
+... 514697358
+... 514770494
+... 514776426
+... 514943174
+... 514966993
+... 515049757
+... 515098671
+... 515110047
+... 515124386
+... 515132082
+... 515170546
+... 515177129
+... 515225233
+... 515259430
+... 515262475
+... 515277440
+... 515278380
+... 515434041
+... 515487668
+... 515558096
+... 515560217
+... 515613776
+... 515985232
+... 515986198
+... 516087152
+... 516091998
+... 516092095
+... 516093150
+... 516093549
+... 516093739
+... 516095544
+... 516095742
+... 516096245
+... 516096351
+... 516096393
+... 516097615
+... 516099157
+... 516099611
+... 516102001
+... 516102266
+... 516104148
+... 516104817
+... 516105012
+... 516105111
+... 516105277
+... 516106002
+... 516106937
+... 516106945
+... 516108453
+... 516109626
+... 516110418
+... 516110913
+... 516112745
+... 516113008
+... 516113461
+... 516113693
+... 516113768
+... 516114865
+... 516114972
+... 516115003
+... 516116340
+... 516117900
+... 516119377
+... 516120169
+... 516120235
+... 516120557
+... 516121530
+... 516121761
+... 516122413
+... 516122645
+... 516123668
+... 516125135
+... 516125424
+... 516125499
+... 516126760
+... 516127941
+... 516128204
+... 516128493
+... 516132602
+... 516132867
+... 516133030
+... 516133113
+... 516133709
+... 516133774
+... 516134012
+... 516134277
+... 516134319
+... 516134392
+... 516134715
+... 516134764
+... 516135977
+... 516136041
+... 516136074
+... 516136264
+... 516136918
+... 516137213
+... 516137270
+... 516137536
+... 516137734
+... 516137775
+... 516138179
+... 516138930
+... 516139060
+... 520037359
+... 520037458
+... 530216845
+... 540165982
+... 540167285
+... 540242070
+... 540256468
+... 540279544
+... 540281359
+... 550011498
+... 550211270
+... 550224299
+... 550240824
+... 550242861
+... 550265193
+...
+... '''
+>>> [x for x in numbers.splitlines() if x and not hp.is_valid(x)]
+[]

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

Summary of changes:
 stdnum/il/__init__.py        |   3 +
 stdnum/il/{idnr.py => hp.py} |  44 ++++----
 tests/test_il_hp.doctest     | 257 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 284 insertions(+), 20 deletions(-)
 copy stdnum/il/{idnr.py => hp.py} (64%)
 create mode 100644 tests/test_il_hp.doctest


hooks/post-receive
-- 
python-stdnum