python-stdnum commit: r128 - in python-stdnum: . stdnum stdnum/at tests
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum commit: r128 - in python-stdnum: . stdnum stdnum/at 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: r128 - in python-stdnum: . stdnum stdnum/at tests
- Date: Mon, 13 Feb 2012 23:11:23 +0100 (CET)
Author: arthur
Date: Mon Feb 13 23:11:22 2012
New Revision: 128
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=128&view=revision
Log:
add a UID (Umsatzsteuer-Identifikationsnummer, Austrian VAT number) module
Added:
python-stdnum/stdnum/at/
python-stdnum/stdnum/at/__init__.py
python-stdnum/stdnum/at/uid.py
Modified:
python-stdnum/README
python-stdnum/stdnum/__init__.py
python-stdnum/tests/test_robustness.doctest
Modified: python-stdnum/README
==============================================================================
--- python-stdnum/README Mon Feb 13 23:02:41 2012 (r127)
+++ python-stdnum/README Mon Feb 13 23:11:22 2012 (r128)
@@ -41,6 +41,7 @@
* CF (Cod de înregistrare în scopuri de TVA, Romanian VAT number)
* Partita IVA (Italian VAT number)
* Αριθμός Εγγραφής Φ.Π.Α. (Cypriot VAT number)
+ * UID (Umsatzsteuer-Identifikationsnummer, Austrian 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 Mon Feb 13 23:02:41 2012 (r127)
+++ python-stdnum/stdnum/__init__.py Mon Feb 13 23:11:22 2012 (r128)
@@ -55,6 +55,7 @@
* CF (Cod de înregistrare în scopuri de TVA, Romanian VAT number)
* Partita IVA (Italian VAT number)
* Αριθμός Εγγραφής Φ.Π.Α. (Cypriot VAT number)
+ * UID (Umsatzsteuer-Identifikationsnummer, Austrian VAT number)
* IMEI (International Mobile Equipment Identity)
* IMSI (International Mobile Subscriber Identity)
* MEID (Mobile Equipment Identifier)
Added: python-stdnum/stdnum/at/__init__.py
==============================================================================
Added: python-stdnum/stdnum/at/uid.py
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ python-stdnum/stdnum/at/uid.py Mon Feb 13 23:11:22 2012 (r128)
@@ -0,0 +1,64 @@
+# vat.py - functions for handling Austrian 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 Austrian UID (Umsatzsteuer-Identifikationsnummer,
+VAT) numbers.
+
+The number is a 9-digit number that always starts with a U (optionally
+preceded with AT). The last digit is a check digit.
+
+>>> compact('AT U13585627')
+'U13585627'
+>>> is_valid('U13585627')
+True
+>>> calc_check_digit('U1358562')
+'7'
+>>> is_valid('U13585626') # incorrect check digit
+False
+"""
+
+from stdnum import luhn
+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('AT'):
+ number = number[2:]
+ return number
+
+
+def calc_check_digit(number):
+ """Calculate the check digit. The number passed should not have the
+ check digit included."""
+ return str((6 - luhn.checksum(number[1:])) % 10)
+
+
+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[0] == 'U' and \
+ number[1:].isdigit() and \
+ calc_check_digit(number[:-1]) == number[-1]
Modified: python-stdnum/tests/test_robustness.doctest
==============================================================================
--- python-stdnum/tests/test_robustness.doctest Mon Feb 13 23:02:41 2012
(r127)
+++ python-stdnum/tests/test_robustness.doctest Mon Feb 13 23:11:22 2012
(r128)
@@ -26,6 +26,7 @@
>>> from stdnum import grid, iban, imei, imsi, isan, isbn, isil, ismn, issn,
>>> ean
>>> from stdnum import luhn, meid, verhoeff
+>>> from stdnum.at import uid
>>> from stdnum.be import vat as be_vat
>>> from stdnum.br import cpf
>>> from stdnum.cy import vat as cy_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: r128 - in python-stdnum: . stdnum stdnum/at tests,
Commits of the python-stdnum project