python-stdnum commit: r174 - in python-stdnum: stdnum stdnum/bg stdnum/cz stdnum/dk stdnum/fi stdnum/lv stdnum/ro tests
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum commit: r174 - in python-stdnum: stdnum stdnum/bg stdnum/cz stdnum/dk stdnum/fi stdnum/lv stdnum/ro tests
- 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: r174 - in python-stdnum: stdnum stdnum/bg stdnum/cz stdnum/dk stdnum/fi stdnum/lv stdnum/ro tests
- Date: Sun, 26 Feb 2012 22:30:34 +0100 (CET)
Author: arthur
Date: Sun Feb 26 22:30:31 2012
New Revision: 174
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=174&view=revision
Log:
re-add Python3 support
Modified:
python-stdnum/stdnum/bg/egn.py
python-stdnum/stdnum/cz/rc.py
python-stdnum/stdnum/dk/cpr.py
python-stdnum/stdnum/fi/hetu.py
python-stdnum/stdnum/isan.py
python-stdnum/stdnum/lv/pvn.py
python-stdnum/stdnum/meid.py
python-stdnum/stdnum/ro/cnp.py
python-stdnum/tests/test_isan.doctest
python-stdnum/tests/test_ismn.doctest
python-stdnum/tests/test_robustness.doctest
Modified: python-stdnum/stdnum/bg/egn.py
==============================================================================
--- python-stdnum/stdnum/bg/egn.py Sun Feb 26 19:55:49 2012 (r173)
+++ python-stdnum/stdnum/bg/egn.py Sun Feb 26 22:30:31 2012 (r174)
@@ -83,7 +83,7 @@
try:
birth_date = get_birth_date(number)
# TODO: check that the birth date is not in the future
- except ValueError, e:
+ except ValueError:
return False
# check the check digit
return calc_check_digit(number[:-1]) == number[-1]
Modified: python-stdnum/stdnum/cz/rc.py
==============================================================================
--- python-stdnum/stdnum/cz/rc.py Sun Feb 26 19:55:49 2012 (r173)
+++ python-stdnum/stdnum/cz/rc.py Sun Feb 26 22:30:31 2012 (r174)
@@ -85,7 +85,7 @@
try:
birth_date = get_birth_date(number)
# TODO: check that the birth date is not in the future
- except ValueError, e:
+ except ValueError:
return False
# check the check digit
if len(number) == 10:
Modified: python-stdnum/stdnum/dk/cpr.py
==============================================================================
--- python-stdnum/stdnum/dk/cpr.py Sun Feb 26 19:55:49 2012 (r173)
+++ python-stdnum/stdnum/dk/cpr.py Sun Feb 26 22:30:31 2012 (r174)
@@ -88,7 +88,7 @@
try:
birth_date = get_birth_date(number)
# TODO: check that the birth date is not in the future
- except ValueError, e:
+ except ValueError:
return False
return True
Modified: python-stdnum/stdnum/fi/hetu.py
==============================================================================
--- python-stdnum/stdnum/fi/hetu.py Sun Feb 26 19:55:49 2012 (r173)
+++ python-stdnum/stdnum/fi/hetu.py Sun Feb 26 22:30:31 2012 (r174)
@@ -81,7 +81,7 @@
# check if birth date is valid
try:
datetime.date(century + year, month, day)
- except ValueError, e:
+ except ValueError:
return False
# for historical reasons individual IDs start from 002
if individual < 2:
Modified: python-stdnum/stdnum/isan.py
==============================================================================
--- python-stdnum/stdnum/isan.py Sun Feb 26 19:55:49 2012 (r173)
+++ python-stdnum/stdnum/isan.py Sun Feb 26 22:30:31 2012 (r174)
@@ -119,7 +119,12 @@
def to_binary(number):
"""Convert the number to it's binary representation (without the check
digits)."""
- return compact(number, strip_check_digits=True).decode('hex')
+ import sys
+ number = compact(number, strip_check_digits=True)
+ if sys.version > '3': # pragma: no cover (Python 2/3 specific code)
+ return bytes.fromhex(number)
+ else:
+ return number.decode('hex')
def to_xml(number):
Modified: python-stdnum/stdnum/lv/pvn.py
==============================================================================
--- python-stdnum/stdnum/lv/pvn.py Sun Feb 26 19:55:49 2012 (r173)
+++ python-stdnum/stdnum/lv/pvn.py Sun Feb 26 22:30:31 2012 (r174)
@@ -97,6 +97,6 @@
try:
birth_date = get_birth_date(number)
# TODO: check that the birth date is not in the future
- except ValueError, e:
+ except ValueError:
return False
return calc_check_digit_pers(number[:-1]) == number[-1]
Modified: python-stdnum/stdnum/meid.py
==============================================================================
--- python-stdnum/stdnum/meid.py Sun Feb 26 19:55:49 2012 (r173)
+++ python-stdnum/stdnum/meid.py Sun Feb 26 22:30:31 2012 (r174)
@@ -150,12 +150,22 @@
return separator.join(x for x in number if x)
+def to_binary(number):
+ """Convert the number to it's binary representation (without the check
+ digit)."""
+ import sys
+ import binascii
+ number = compact(number, strip_check_digit=True)
+ if sys.version > '3': # pragma: no cover (Python 2/3 specific code)
+ return bytes.fromhex(number)
+ else:
+ return number.decode('hex')
+
+
def to_pseudo_esn(number):
"""Convert the provided MEID to a pseudo ESN (pESN). The ESN is returned
in compact HEX representation."""
import hashlib
- # get the SHA1 of the binary representation of the number
- s = hashlib.sha1(compact(number, strip_check_digit=True).decode('hex'))
- # return the last 6 digits of the hash prefixed with the reserved
+ # return the last 6 digits of the SHA1 hash prefixed with the reserved
# manufacturer code
- return '80' + s.hexdigest()[-6:].upper()
+ return '80' + hashlib.sha1(to_binary(number)).hexdigest()[-6:].upper()
Modified: python-stdnum/stdnum/ro/cnp.py
==============================================================================
--- python-stdnum/stdnum/ro/cnp.py Sun Feb 26 19:55:49 2012 (r173)
+++ python-stdnum/stdnum/ro/cnp.py Sun Feb 26 22:30:31 2012 (r174)
@@ -82,7 +82,7 @@
try:
birth_date = get_birth_date(number)
# TODO: check that the birth date is not in the future
- except ValueError, e:
+ except ValueError:
return False
# number[7:9] is the county, we ignore it for now, just check last digit
return calc_check_digit(number[:-1]) == number[-1]
Modified: python-stdnum/tests/test_isan.doctest
==============================================================================
--- python-stdnum/tests/test_isan.doctest Sun Feb 26 19:55:49 2012
(r173)
+++ python-stdnum/tests/test_isan.doctest Sun Feb 26 22:30:31 2012
(r174)
@@ -87,5 +87,10 @@
A simple test for the to_binary() function.
->>> isan.to_binary('0000-0000-D07A-0090-Q').encode('hex')
+>>> import binascii
+>>> import sys
+>>> x = binascii.b2a_hex(isan.to_binary('0000-0000-D07A-0090-Q'))
+>>> if sys.version > '3':
+... x = str(x, encoding='ascii')
+>>> x
'00000000d07a0090'
Modified: python-stdnum/tests/test_ismn.doctest
==============================================================================
--- python-stdnum/tests/test_ismn.doctest Sun Feb 26 19:55:49 2012
(r173)
+++ python-stdnum/tests/test_ismn.doctest Sun Feb 26 22:30:31 2012
(r174)
@@ -29,7 +29,7 @@
>>> ismn.is_valid('979-0-3217-6543-6')
True
->>> ismn.is_valid(u'979-0-3217-6544-3')
+>>> ismn.is_valid('979-0-3217-6544-3')
True
>>> ismn.is_valid('9790321765450')
True
Modified: python-stdnum/tests/test_robustness.doctest
==============================================================================
--- python-stdnum/tests/test_robustness.doctest Sun Feb 26 19:55:49 2012
(r173)
+++ python-stdnum/tests/test_robustness.doctest Sun Feb 26 22:30:31 2012
(r174)
@@ -27,7 +27,8 @@
Go over each module and try every value.
+>>> badmodules = []
>>> for mod in get_number_modules():
... results = [ x for x in testvalues if mod.is_valid(x) != False ]
... if results:
-... print mod.__name__, results
+... print(mod.__name__, results)
--
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: r174 - in python-stdnum: stdnum stdnum/bg stdnum/cz stdnum/dk stdnum/fi stdnum/lv stdnum/ro tests,
Commits of the python-stdnum project