python-stdnum branch master updated. 1.18-15-gcf14a9f
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum branch master updated. 1.18-15-gcf14a9f
- 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, python-stdnum-commits [at] lists.arthurdejong.org
- Subject: python-stdnum branch master updated. 1.18-15-gcf14a9f
- Date: Sun, 2 Apr 2023 18:49:58 +0200 (CEST)
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 cf14a9ff079b53da57c7e17e7a5686734795285e (commit)
from a8b6573d076793ebd58cf97ac9d903cb36a9a6b1 (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=cf14a9ff079b53da57c7e17e7a5686734795285e
commit cf14a9ff079b53da57c7e17e7a5686734795285e
Author: RaduBorzea <101399404+RaduBorzea@users.noreply.github.com>
Date: Mon Mar 6 16:39:29 2023 +0200
Add get_county() function to Romanian CNP
This also validates the county part of the number.
Closes https://github.com/arthurdejong/python-stdnum/pull/407
diff --git a/stdnum/ro/cnp.py b/stdnum/ro/cnp.py
index 90ff313..44e02e8 100644
--- a/stdnum/ro/cnp.py
+++ b/stdnum/ro/cnp.py
@@ -26,9 +26,12 @@ gender, birth date and country zone.
More information:
* https://ro.wikipedia.org/wiki/Cod_numeric_personal
+* https://github.com/vimishor/cnp-spec/blob/master/spec.md
>>> validate('1630615123457')
'1630615123457'
+>>> get_county('1630615123457')
+'Cluj'
>>> validate('0800101221142') # invalid first digit
Traceback (most recent call last):
...
@@ -37,6 +40,10 @@ InvalidComponent: ...
Traceback (most recent call last):
...
InvalidComponent: ...
+>>> validate('1630615993454') # invalid county
+Traceback (most recent call last):
+ ...
+InvalidComponent: ...
>>> validate('1630615123458') # invalid check digit
Traceback (most recent call last):
...
@@ -49,6 +56,61 @@ from stdnum.exceptions import *
from stdnum.util import clean, isdigits
+# The Romanian counties
+_COUNTIES = {
+ '01': 'Alba',
+ '02': 'Arad',
+ '03': 'Arges',
+ '04': 'Bacau',
+ '05': 'Bihor',
+ '06': 'Bistrita-Nasaud',
+ '07': 'Botosani',
+ '08': 'Brasov',
+ '09': 'Braila',
+ '10': 'Buzau',
+ '11': 'Caras-Severin',
+ '12': 'Cluj',
+ '13': 'Constanta',
+ '14': 'Covasna',
+ '15': 'Dambovita',
+ '16': 'Dolj',
+ '17': 'Galati',
+ '18': 'Gorj',
+ '19': 'Harghita',
+ '20': 'Hunedoara',
+ '21': 'Ialomita',
+ '22': 'Iasi',
+ '23': 'Ilfov',
+ '24': 'Maramures',
+ '25': 'Mehedinti',
+ '26': 'Mures',
+ '27': 'Neamt',
+ '28': 'Olt',
+ '29': 'Prahova',
+ '30': 'Satu Mare',
+ '31': 'Salaj',
+ '32': 'Sibiu',
+ '33': 'Suceava',
+ '34': 'Teleorman',
+ '35': 'Timis',
+ '36': 'Tulcea',
+ '37': 'Vaslui',
+ '38': 'Valcea',
+ '39': 'Vrancea',
+ '40': 'Bucuresti',
+ '41': 'Bucuresti - Sector 1',
+ '42': 'Bucuresti - Sector 2',
+ '43': 'Bucuresti - Sector 3',
+ '44': 'Bucuresti - Sector 4',
+ '45': 'Bucuresti - Sector 5',
+ '46': 'Bucuresti - Sector 6',
+ '47': 'Bucuresti - Sector 7 (desfiintat)',
+ '48': 'Bucuresti - Sector 8 (desfiintat)',
+ '51': 'Calarasi',
+ '52': 'Giurgiu',
+}
+
+
def compact(number):
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
@@ -78,6 +140,14 @@ def get_birth_date(number):
raise InvalidComponent()
+def get_county(number):
+ """Get the county name from the number"""
+ try:
+ return _COUNTIES[compact(number)[7:9]]
+ except KeyError:
+ raise InvalidComponent()
+
+
def validate(number):
"""Check if the number is a valid VAT number. This checks the length,
formatting and check digit."""
@@ -93,7 +163,7 @@ def validate(number):
# check if birth date is valid
get_birth_date(number)
# TODO: check that the birth date is not in the future
- # number[7:9] is the county, we ignore it for now, just check last digit
+ get_county(number)
if calc_check_digit(number[:-1]) != number[-1]:
raise InvalidChecksum()
return number
-----------------------------------------------------------------------
Summary of changes:
stdnum/ro/cnp.py | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 71 insertions(+), 1 deletion(-)
hooks/post-receive
--
python-stdnum
- python-stdnum branch master updated. 1.18-15-gcf14a9f,
Commits of the python-stdnum project