python-stdnum branch master updated. 1.6-16-g53cc0dc
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum branch master updated. 1.6-16-g53cc0dc
- From: Commits of the python-stdnum project <python-stdnum-commits [at] lists.arthurdejong.org>
- To: python-stdnum-commits [at] lists.arthurdejong.org
- Reply-to: python-stdnum-users [at] lists.arthurdejong.org
- Subject: python-stdnum branch master updated. 1.6-16-g53cc0dc
- Date: Sun, 3 Sep 2017 21:33:31 +0200 (CEST)
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
discards 707b63c42493ce700a1c3f8c624626e969702766 (commit)
via 53cc0dca1a3a5a7f4d543c5527c70cddfdf9f32b (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (707b63c42493ce700a1c3f8c624626e969702766)
\
N -- N -- N (53cc0dca1a3a5a7f4d543c5527c70cddfdf9f32b)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
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=53cc0dca1a3a5a7f4d543c5527c70cddfdf9f32b
commit 53cc0dca1a3a5a7f4d543c5527c70cddfdf9f32b
Author: Mohammed Salman <mohammed@holvi.com>
Date: Fri Aug 25 04:56:20 2017 +0300
Add support for German tax id number
diff --git a/stdnum/de/idnr.py b/stdnum/de/idnr.py
new file mode 100644
index 0000000..a9952fd
--- /dev/null
+++ b/stdnum/de/idnr.py
@@ -0,0 +1,94 @@
+# idnr.py - functions for handling German tax id
+# coding: utf-8
+#
+# Copyright (C) 2017 Holvi Payment Services Oy
+# 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
+
+"""IdNr (Steuerliche Identifikationsnummer, German personal tax number).
+
+The IdNr (or Steuer-IdNr) is a personal identification number that is
+assigned to individuals in Germany for tax purposes and is meant to replace
+the Steuernummer. The number consists of 11 digits and does not embed any
+personal information.
+
+More information:
+
+* https://de.wikipedia.org/wiki/Steuerliche_Identifikationsnummer
+* http://www.identifikationsmerkmal.de/
+
+>>> validate('36 574 261 809')
+'36574261809'
+>>> validate('36574261890')
+Traceback (most recent call last):
+ ...
+InvalidChecksum: ...
+>>> validate('36554266806') # more digits repeated
+Traceback (most recent call last):
+ ...
+InvalidFormat: ...
+>>> format('36574261809')
+'36 574 261 809'
+"""
+
+from collections import defaultdict
+
+from stdnum.exceptions import *
+from stdnum.iso7064 import mod_11_10
+from stdnum.util import clean
+
+
+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 to see if the number provided is a valid tax identification
+ number. This checks the length, formatting and check digit."""
+ number = compact(number)
+ if len(number) != 11:
+ raise InvalidLength()
+ if not number.isdigit():
+ raise InvalidFormat()
+ if number.startswith('0'):
+ raise InvalidFormat()
+ # In the first 10 digits exactly one digit must be repeated two or
+ # three times and other digits can appear only once.
+ counter = defaultdict(int)
+ for n in number[:10]:
+ counter[n] += 1
+ counts = [c for c in counter.values() if c > 1]
+ if len(counts) != 1 or counts[0] not in (2, 3):
+ raise InvalidFormat()
+ return mod_11_10.validate(number)
+
+
+def is_valid(number):
+ """Checks to see if the number provided is a valid tax identification
+ number. This checks the length, formatting and check digit."""
+ try:
+ return bool(validate(number))
+ except ValidationError:
+ return False
+
+
+def format(number):
+ """Reformat the passed number to the standard format."""
+ number = compact(number)
+ return ' '.join((number[:2], number[2:5], number[5:8], number[8:]))
diff --git a/tests/test_de_idnr.doctest b/tests/test_de_idnr.doctest
new file mode 100644
index 0000000..ecd65ed
--- /dev/null
+++ b/tests/test_de_idnr.doctest
@@ -0,0 +1,66 @@
+test_de_idnr.doctest - more detailed doctests for stdnum.de.idnr module
+
+Copyright (C) 2017 Holvi Payment Services Oy
+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.de.idnr module. It
+tries to test more corner cases and detailed functionality that is not really
+useful as module documentation.
+
+>>> from stdnum.de import idnr
+
+
+The number should be 11 digits long, should contain only numbers and cannot
+start with a zero.
+
+>>> idnr.validate('116574261809')
+Traceback (most recent call last):
+ ...
+InvalidLength: ...
+>>> idnr.validate('A6574261809')
+Traceback (most recent call last):
+ ...
+InvalidFormat: ...
+>>> idnr.validate('01234567896')
+Traceback (most recent call last):
+ ...
+InvalidFormat: ...
+
+
+The first 10 digits of the IdNr is supposed to contain extactly one digit
+twice (or three times since 2016) and all other digits in the number can only
+appear once. This tries to catch some corner cases. Note that only the first
+10 digits are considered for this.
+
+>>> idnr.validate('1234567890 3') # each digit once
+Traceback (most recent call last):
+ ...
+InvalidFormat: ...
+>>> idnr.validate('1123456789 0') # one digit twice
+'11234567890'
+>>> idnr.validate('1112345678 6') # one digit three times
+'11123456786'
+>>> idnr.validate('1111234567 8') # one digit four times
+Traceback (most recent call last):
+ ...
+InvalidFormat: ...
+>>> idnr.validate('1122345678 5') # two digits more than once
+Traceback (most recent call last):
+ ...
+InvalidFormat: ...
-----------------------------------------------------------------------
Summary of changes:
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/
- python-stdnum branch master updated. 1.6-16-g53cc0dc,
Commits of the python-stdnum project