python-stdnum commit: r160 - in python-stdnum: . stdnum stdnum/ie
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum commit: r160 - in python-stdnum: . stdnum stdnum/ie
- 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: r160 - in python-stdnum: . stdnum stdnum/ie
- Date: Thu, 23 Feb 2012 22:58:20 +0100 (CET)
Author: arthur
Date: Thu Feb 23 22:58:18 2012
New Revision: 160
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=160&view=revision
Log:
add a PPS No (Personal Public Service Number, Irish personal number) module
Added:
python-stdnum/stdnum/ie/pps.py
Modified:
python-stdnum/README
python-stdnum/stdnum/__init__.py
Modified: python-stdnum/README
==============================================================================
--- python-stdnum/README Wed Feb 22 22:17:28 2012 (r159)
+++ python-stdnum/README Thu Feb 23 22:58:18 2012 (r160)
@@ -33,6 +33,7 @@
* EGN (ЕГН, Единен граждански номер, Bulgarian personal identity codes)
* PNF (ЛНЧ, Личен номер на чужденец, Bulgarian personal number of a foreigner)
* OIB (Osobni identifikacijski broj, Croatian personal identification number)
+ * PPS No (Personal Public Service Number, Irish personal number)
* NIF (Número de Identificación Fiscal, Spanish VAT number)
* FPA, ΦΠΑ (Foros Prostithemenis Aksias, the Greek VAT number)
* Ust ID Nr. (Umsatzsteur Identifikationnummer, the German VAT number)
Modified: python-stdnum/stdnum/__init__.py
==============================================================================
--- python-stdnum/stdnum/__init__.py Wed Feb 22 22:17:28 2012 (r159)
+++ python-stdnum/stdnum/__init__.py Thu Feb 23 22:58:18 2012 (r160)
@@ -47,6 +47,7 @@
* EGN (ЕГН, Единен граждански номер, Bulgarian personal identity codes)
* PNF (ЛНЧ, Личен номер на чужденец, Bulgarian personal number of a foreigner)
* OIB (Osobni identifikacijski broj, Croatian personal identification number)
+ * PPS No (Personal Public Service Number, Irish personal number)
* NIF (Número de Identificación Fiscal, Spanish VAT number)
* FPA, ΦΠΑ (Foros Prostithemenis Aksias, the Greek VAT number)
* Ust ID Nr. (Umsatzsteur Identifikationnummer, the German VAT number)
Added: python-stdnum/stdnum/ie/pps.py
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ python-stdnum/stdnum/ie/pps.py Thu Feb 23 22:58:18 2012 (r160)
@@ -0,0 +1,60 @@
+# pps.py - functions for handling Irish PPS 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 Irish PPS (Personal Public Service) numbers.
+
+The number consists of 8 digits. The first seven are numeric and the last
+is the check character. The number is sometimes be followed by an extra
+letter, which is ignored for the check algorithm, and can be a 'W', 'T' or
+an 'X'.
+
+>>> compact('6433435F')
+'6433435F'
+>>> is_valid('6433435F')
+True
+>>> is_valid('6433435E') # incorrect check digit
+False
+"""
+
+import re
+
+from stdnum.util import clean
+from stdnum.ie import vat
+
+
+pps_re = re.compile('^\d{7}[A-W][WTX]?$')
+"""Regular expression used to check syntax of PPS numbers."""
+
+
+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, ' -').upper().strip()
+
+
+def is_valid(number):
+ """Checks to see if the number provided is a valid PPS number. This
+ checks the length, formatting and check digit."""
+ try:
+ number = compact(number)
+ except:
+ return False
+ if not pps_re.match(number):
+ return False
+ return number[7] == vat.calc_check_digit(number[:7])
--
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: r160 - in python-stdnum: . stdnum stdnum/ie,
Commits of the python-stdnum project