[Python-modules-commits] r20587 - in packages/python-stdnum/trunk/debian (4 files)

adejong at users.alioth.debian.org adejong at users.alioth.debian.org
Sun Feb 26 22:20:07 UTC 2012


    Date: Sunday, February 26, 2012 @ 22:20:06
  Author: adejong
Revision: 20587

  * Add a patch from upstream to re-add support for Python3.

Added:
  packages/python-stdnum/trunk/debian/patches/
  packages/python-stdnum/trunk/debian/patches/series
  packages/python-stdnum/trunk/debian/patches/support-python3.patch
Modified:
  packages/python-stdnum/trunk/debian/changelog

Modified: packages/python-stdnum/trunk/debian/changelog
===================================================================
--- packages/python-stdnum/trunk/debian/changelog	2012-02-26 21:47:55 UTC (rev 20586)
+++ packages/python-stdnum/trunk/debian/changelog	2012-02-26 22:20:06 UTC (rev 20587)
@@ -48,8 +48,9 @@
       Sphinx
   * Add missing dependency on pkg_resources package (closes: #654782)
   * Switch to Version 1.0 debian/copyright format.
+  * Add a patch from upstream to re-add support for Python3.
 
- -- Arthur de Jong <adejong at debian.org>  Sun, 26 Feb 2012 22:30:00 +0100
+ -- Arthur de Jong <adejong at debian.org>  Sun, 26 Feb 2012 23:15:00 +0100
 
 python-stdnum (0.6-1) unstable; urgency=low
 

Added: packages/python-stdnum/trunk/debian/patches/series
===================================================================
--- packages/python-stdnum/trunk/debian/patches/series	                        (rev 0)
+++ packages/python-stdnum/trunk/debian/patches/series	2012-02-26 22:20:06 UTC (rev 20587)
@@ -0,0 +1 @@
+support-python3.patch

Added: packages/python-stdnum/trunk/debian/patches/support-python3.patch
===================================================================
--- packages/python-stdnum/trunk/debian/patches/support-python3.patch	                        (rev 0)
+++ packages/python-stdnum/trunk/debian/patches/support-python3.patch	2012-02-26 22:20:06 UTC (rev 20587)
@@ -0,0 +1,150 @@
+Description: Re-add support for Python3
+Origin: upstream, http://arthurdejong.org/trac/python-stdnum/changeset/174
+
+--- a/tests/test_ismn.doctest
++++ b/tests/test_ismn.doctest
+@@ -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
+--- a/tests/test_robustness.doctest
++++ b/tests/test_robustness.doctest
+@@ -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)
+--- a/tests/test_isan.doctest
++++ b/tests/test_isan.doctest
+@@ -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'
+--- a/stdnum/bg/egn.py
++++ b/stdnum/bg/egn.py
+@@ -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]
+--- a/stdnum/dk/cpr.py
++++ b/stdnum/dk/cpr.py
+@@ -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
+
+--- a/stdnum/fi/hetu.py
++++ b/stdnum/fi/hetu.py
+@@ -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:
+--- a/stdnum/meid.py
++++ b/stdnum/meid.py
+@@ -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()
+--- a/stdnum/ro/cnp.py
++++ b/stdnum/ro/cnp.py
+@@ -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]
+--- a/stdnum/lv/pvn.py
++++ b/stdnum/lv/pvn.py
+@@ -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]
+--- a/stdnum/isan.py
++++ b/stdnum/isan.py
+@@ -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):
+--- a/stdnum/cz/rc.py
++++ b/stdnum/cz/rc.py
+@@ -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:




More information about the Python-modules-commits mailing list