python-stdnum commit: r104 - in python-stdnum: . stdnum stdnum/de tests
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum commit: r104 - in python-stdnum: . stdnum stdnum/de tests
- 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 commit: r104 - in python-stdnum: . stdnum stdnum/de tests
- Date: Fri, 10 Feb 2012 14:16:59 +0100 (CET)
Author: arthur
Date: Fri Feb 10 14:16:58 2012
New Revision: 104
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=104&view=revision
Log:
add an Ust ID Nr. (Umsatzsteur Identifikationnummer, the German VAT number)
module
Added:
python-stdnum/stdnum/de/
python-stdnum/stdnum/de/__init__.py
python-stdnum/stdnum/de/vat.py
Modified:
python-stdnum/README
python-stdnum/stdnum/__init__.py
python-stdnum/tests/test_robustness.doctest
Modified: python-stdnum/README
==============================================================================
--- python-stdnum/README Fri Feb 10 14:06:31 2012 (r103)
+++ python-stdnum/README Fri Feb 10 14:16:58 2012 (r104)
@@ -25,6 +25,7 @@
* SSN (U.S. Social Security Number)
* HETU (Finnish personal identity code)
* FPA, ΦΠΑ (Foros Prostithemenis Aksias, the Greek VAT number)
+ * Ust ID Nr. (Umsatzsteur Identifikationnummer, the German VAT number)
* IMEI (International Mobile Equipment Identity)
* IMSI (International Mobile Subscriber Identity)
* MEID (Mobile Equipment Identifier)
Modified: python-stdnum/stdnum/__init__.py
==============================================================================
--- python-stdnum/stdnum/__init__.py Fri Feb 10 14:06:31 2012 (r103)
+++ python-stdnum/stdnum/__init__.py Fri Feb 10 14:16:58 2012 (r104)
@@ -39,6 +39,7 @@
* SSN (U.S. Social Security Number)
* HETU (Finnish personal identity code)
* FPA, ΦΠΑ (Foros Prostithemenis Aksias, the Greek VAT number)
+ * Ust ID Nr. (Umsatzsteur Identifikationnummer, the German VAT number)
* IMEI (International Mobile Equipment Identity)
* IMSI (International Mobile Subscriber Identity)
* MEID (Mobile Equipment Identifier)
Added: python-stdnum/stdnum/de/__init__.py
==============================================================================
Added: python-stdnum/stdnum/de/vat.py
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ python-stdnum/stdnum/de/vat.py Fri Feb 10 14:16:58 2012 (r104)
@@ -0,0 +1,53 @@
+# vat.py - functions for handling German VAT numbers
+#
+# Copyright (C) 2012 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
+
+
+"""Module for handling German VAT (Umsatzsteur Identifikationnummer, Ust
+ID Nr.) numbers.
+
+>>> compact('DE 136,695 976')
+'136695976'
+>>> is_valid('DE136695976')
+True
+>>> is_valid('136695978')
+False
+"""
+
+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."""
+ number = clean(number, ' -./,').upper().strip()
+ if number.startswith('DE'):
+ number = number[2:]
+ return number
+
+
+def is_valid(number):
+ """Checks to see if the number provided is a valid VAT number. This checks
+ the length, formatting and check digit."""
+ try:
+ number = compact(number)
+ except:
+ return False
+ return len(number) == 9 and number.isdigit() and \
+ number[0] != '0' and mod_11_10.is_valid(number)
Modified: python-stdnum/tests/test_robustness.doctest
==============================================================================
--- python-stdnum/tests/test_robustness.doctest Fri Feb 10 14:06:31 2012
(r103)
+++ python-stdnum/tests/test_robustness.doctest Fri Feb 10 14:16:58 2012
(r104)
@@ -28,6 +28,7 @@
>>> from stdnum import luhn, meid, verhoeff
>>> from stdnum.br import cpf
>>> from stdnum.cz import rc
+>>> from stdnum.de import vat as de_vat
>>> from stdnum.fi import hetu
>>> from stdnum.fr import siren
>>> from stdnum.gr import vat as gr_vat
--
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits/
- python-stdnum commit: r104 - in python-stdnum: . stdnum stdnum/de tests,
Commits of the python-stdnum project