python-stdnum branch master updated. 1.7-19-gc576bc4
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum branch master updated. 1.7-19-gc576bc4
- 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.7-19-gc576bc4
- Date: Fri, 1 Dec 2017 11:33:25 +0100 (CET)
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 c576bc44aef61686eab0d8b23363da6b879cef25 (commit)
from bafdb70b54262633d9c4bb865ba8efbc4b1fdaa9 (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=c576bc44aef61686eab0d8b23363da6b879cef25
commit c576bc44aef61686eab0d8b23363da6b879cef25
Author: srikanthlogic <srik.lak@gmail.com>
Date: Fri Dec 1 11:14:13 2017 +0530
Add Indian Aadhaar
Closes https://github.com/arthurdejong/python-stdnum/pull/56
diff --git a/stdnum/in_/__init__.py b/stdnum/in_/__init__.py
new file mode 100644
index 0000000..5226bd0
--- /dev/null
+++ b/stdnum/in_/__init__.py
@@ -0,0 +1,21 @@
+# __init__.py - collection of Indian numbers
+# coding: utf-8
+#
+# Copyright (C) 2017 Srikanth Lakshmanan
+#
+# 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
+
+"""Collection of Indian numbers."""
diff --git a/stdnum/in_/aadhaar.py b/stdnum/in_/aadhaar.py
new file mode 100644
index 0000000..eb57b95
--- /dev/null
+++ b/stdnum/in_/aadhaar.py
@@ -0,0 +1,98 @@
+# aadhaar.py - functions for handling Indian Aadhaar numbers
+#
+# Copyright (C) 2017 Srikanth L
+#
+# 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
+
+"""Aadhaar (Indian digital resident personal identity number)
+
+Aadhaar is a 12 digit unique identity number issued to all Indian residents.
+The number is assigned by the Unique Identification Authority of India
+(UIDAI).
+
+More information:
+
+* https://en.wikipedia.org/wiki/Aadhaar
+
+>>> validate('234123412346')
+'234123412346'
+>>> validate('234123412347')
+Traceback (most recent call last):
+ ...
+InvalidChecksum: ...
+>>> validate('123412341234') # number should not start with 0 or 1
+Traceback (most recent call last):
+ ...
+InvalidFormat: ...
+>>> validate('643343121')
+Traceback (most recent call last):
+ ...
+InvalidLength: ...
+>>> format('234123412346')
+'2341 2341 2346'
+>>> mask('234123412346')
+'XXXX XXXX 2346'
+"""
+
+import re
+
+from stdnum import verhoeff
+from stdnum.exceptions import *
+from stdnum.util import clean
+
+
+aadhaar_re = re.compile(r'^[2-9][0-9]{11}$')
+"""Regular expression used to check syntax of Aadhaar 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, ' -').strip()
+
+
+def validate(number):
+ """Check if the number provided is a valid Aadhaar number. This checks
+ the length, formatting and check digit."""
+ number = compact(number)
+ if len(number) != 12:
+ raise InvalidLength()
+ if not aadhaar_re.match(number):
+ raise InvalidFormat()
+ verhoeff.validate(number)
+ return number
+
+
+def is_valid(number):
+ """Check if the number provided is a valid Aadhaar number. 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."""
+ number = compact(number)
+ return ' '.join((number[:4], number[4:8], number[8:]))
+
+
+def mask(number):
+ """Masks the first 8 digits as per MeitY guidelines for securing identity
+ information and Sensitive personal data."""
+ number = compact(number)
+ return 'XXXX XXXX ' + number[-4:]
-----------------------------------------------------------------------
Summary of changes:
stdnum/{ch => in_}/__init__.py | 6 +--
stdnum/{br/cpf.py => in_/aadhaar.py} | 76 ++++++++++++++++++++----------------
2 files changed, 46 insertions(+), 36 deletions(-)
copy stdnum/{ch => in_}/__init__.py (85%)
copy stdnum/{br/cpf.py => in_/aadhaar.py} (50%)
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.7-19-gc576bc4,
Commits of the python-stdnum project