Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/stdnum/es
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2019-04-28 23:35:42 +0200
committerArthur de Jong <arthur@arthurdejong.org>2019-04-29 21:31:14 +0200
commit48ff92e300696e2449070ac03b4916c76d4e77a3 (patch)
tree7cbdf6e9e626bd2cac7b98ca2ad5ac7436d5cdaa /stdnum/es
parent3aeec68735d75a4835122990bef232ed415b07d5 (diff)
Use an internal isdigits() function instead of str.isdigit()
The problem with the latter is that it will also accept all kinds of unicode digits that are not the ASCII 0-9 digits causing all kinds of problems in check digit calculations. Some of these unicode characters are also considered digits by int() but some are not (such as the SUPERSCRIPT TWO unicode character). Closes https://github.com/arthurdejong/python-stdnum/issues/96
Diffstat (limited to 'stdnum/es')
-rw-r--r--stdnum/es/ccc.py4
-rw-r--r--stdnum/es/cif.py3
-rw-r--r--stdnum/es/cups.py6
-rw-r--r--stdnum/es/dni.py4
-rw-r--r--stdnum/es/nie.py3
-rw-r--r--stdnum/es/nif.py6
6 files changed, 14 insertions, 12 deletions
diff --git a/stdnum/es/ccc.py b/stdnum/es/ccc.py
index 69a4105..b9e1db1 100644
--- a/stdnum/es/ccc.py
+++ b/stdnum/es/ccc.py
@@ -63,7 +63,7 @@ InvalidChecksum: ...
"""
from stdnum.exceptions import *
-from stdnum.util import clean
+from stdnum.util import clean, isdigits
def compact(number):
@@ -103,7 +103,7 @@ def validate(number):
number = compact(number)
if len(number) != 20:
raise InvalidLength()
- if not number.isdigit():
+ if not isdigits(number):
raise InvalidFormat()
if number[8:10] != calc_check_digits(number):
raise InvalidChecksum()
diff --git a/stdnum/es/cif.py b/stdnum/es/cif.py
index 8802f87..982cdff 100644
--- a/stdnum/es/cif.py
+++ b/stdnum/es/cif.py
@@ -49,6 +49,7 @@ InvalidFormat: ...
from stdnum import luhn
from stdnum.es import dni
from stdnum.exceptions import *
+from stdnum.util import isdigits
__all__ = ['compact', 'validate', 'is_valid', 'split']
@@ -70,7 +71,7 @@ def validate(number):
"""Check if the number provided is a valid DNI number. This checks the
length, formatting and check digit."""
number = compact(number)
- if not number[1:-1].isdigit():
+ if not isdigits(number[1:-1]):
raise InvalidFormat()
if len(number) != 9:
raise InvalidLength()
diff --git a/stdnum/es/cups.py b/stdnum/es/cups.py
index 896240a..895bcc2 100644
--- a/stdnum/es/cups.py
+++ b/stdnum/es/cups.py
@@ -54,7 +54,7 @@ InvalidChecksum: ...
"""
from stdnum.exceptions import *
-from stdnum.util import clean
+from stdnum.util import clean, isdigits
def compact(number):
@@ -92,11 +92,11 @@ def validate(number):
raise InvalidLength()
if number[:2] != 'ES':
raise InvalidComponent()
- if not number[2:18].isdigit():
+ if not isdigits(number[2:18]):
raise InvalidFormat()
if number[20:]:
pnumber, ptype = number[20:]
- if not pnumber.isdigit():
+ if not isdigits(pnumber):
raise InvalidFormat()
if ptype not in 'FPRCXYZ':
raise InvalidFormat()
diff --git a/stdnum/es/dni.py b/stdnum/es/dni.py
index 9b529ef..d255efd 100644
--- a/stdnum/es/dni.py
+++ b/stdnum/es/dni.py
@@ -39,7 +39,7 @@ InvalidLength: ...
"""
from stdnum.exceptions import *
-from stdnum.util import clean
+from stdnum.util import clean, isdigits
def compact(number):
@@ -58,7 +58,7 @@ def validate(number):
"""Check if the number provided is a valid DNI number. This checks the
length, formatting and check digit."""
number = compact(number)
- if not number[:-1].isdigit():
+ if not isdigits(number[:-1]):
raise InvalidFormat()
if len(number) != 9:
raise InvalidLength()
diff --git a/stdnum/es/nie.py b/stdnum/es/nie.py
index 91c5918..1bd2325 100644
--- a/stdnum/es/nie.py
+++ b/stdnum/es/nie.py
@@ -38,6 +38,7 @@ InvalidLength: ...
from stdnum.es import dni
from stdnum.exceptions import *
+from stdnum.util import isdigits
__all__ = ['compact', 'calc_check_digit', 'validate', 'is_valid']
@@ -59,7 +60,7 @@ def validate(number):
"""Check if the number provided is a valid NIE. This checks the length,
formatting and check digit."""
number = compact(number)
- if not number[1:-1].isdigit() or number[:1] not in 'XYZ':
+ if not isdigits(number[1:-1]) or number[:1] not in 'XYZ':
raise InvalidFormat()
if len(number) != 9:
raise InvalidLength()
diff --git a/stdnum/es/nif.py b/stdnum/es/nif.py
index b99049d..af7e1f4 100644
--- a/stdnum/es/nif.py
+++ b/stdnum/es/nif.py
@@ -46,7 +46,7 @@ InvalidChecksum: ...
from stdnum.es import cif, dni, nie
from stdnum.exceptions import *
-from stdnum.util import clean
+from stdnum.util import clean, isdigits
def compact(number):
@@ -62,7 +62,7 @@ def validate(number):
"""Check if the number provided is a valid VAT number. This checks the
length, formatting and check digit."""
number = compact(number)
- if not number[1:-1].isdigit():
+ if not isdigits(number[1:-1]):
raise InvalidFormat()
if len(number) != 9:
raise InvalidLength()
@@ -73,7 +73,7 @@ def validate(number):
# these use the old checkdigit algorithm (the DNI one)
if number[-1] != dni.calc_check_digit(number[1:-1]):
raise InvalidChecksum()
- elif number[0].isdigit():
+ elif isdigits(number[0]):
# natural resident
dni.validate(number)
elif number[0] in 'XYZ':