lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.10-8-gd7f7b8e

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 1.10-8-gd7f7b8e



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  d7f7b8e577f613226011f6b00a8a024d5072fe0d (commit)
      from  375f63b76fccc89ce0ee9b4246e5fb9a2400d1eb (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=d7f7b8e577f613226011f6b00a8a024d5072fe0d

commit d7f7b8e577f613226011f6b00a8a024d5072fe0d
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Thu Dec 27 20:06:02 2018 +0100

    Add Argentinian DNI
    
    Closes https://github.com/arthurdejong/python-stdnum/issues/90

diff --git a/stdnum/ar/__init__.py b/stdnum/ar/__init__.py
index 8a0ff08..6e99d4e 100644
--- a/stdnum/ar/__init__.py
+++ b/stdnum/ar/__init__.py
@@ -20,5 +20,6 @@
 
 """Collection of Argentinian numbers."""
 
-# provide vat as an alias
+# provide aliases
 from stdnum.ar import cuit as vat  # noqa: F401
+from stdnum.ar import dni as personalid  # noqa: F401
diff --git a/stdnum/ar/dni.py b/stdnum/ar/dni.py
new file mode 100644
index 0000000..510018f
--- /dev/null
+++ b/stdnum/ar/dni.py
@@ -0,0 +1,72 @@
+# dni.py - functions for handling Argentinian national identifiers
+# coding: utf-8
+#
+# Copyright (C) 2018 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
+
+"""DNI (Documento Nacional de Identidad, Argentinian national identity nr.).
+
+The DNI number is the number that appears on the Argentinian national
+identity document and is used to identify citizen and foreigners residing in
+the country.
+
+More information:
+
+* https://en.wikipedia.org/wiki/Documento_Nacional_de_Identidad_(Argentina)
+
+>>> validate('20.123.456')
+'20123456'
+>>> validate('2012345699')
+Traceback (most recent call last):
+    ...
+InvalidLength: ...
+>>> format('20123456')
+'20.123.456'
+"""
+
+from stdnum.exceptions import *
+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):
+    """Check if the number is a valid DNI."""
+    number = compact(number)
+    if not number.isdigit():
+        raise InvalidFormat()
+    if len(number) not in (7, 8):
+        raise InvalidLength()
+    return number
+
+
+def is_valid(number):
+    """Check if the number is a valid DNI."""
+    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[:-6], number[-6:-3], number[-3:]))

-----------------------------------------------------------------------

Summary of changes:
 stdnum/ar/__init__.py           |  3 ++-
 stdnum/{no/mva.py => ar/dni.py} | 46 ++++++++++++++++++++---------------------
 2 files changed, 25 insertions(+), 24 deletions(-)
 copy stdnum/{no/mva.py => ar/dni.py} (60%)


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/