python-stdnum commit: r100 - in python-stdnum/stdnum: . br nl us
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum commit: r100 - in python-stdnum/stdnum: . br nl us
- 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: r100 - in python-stdnum/stdnum: . br nl us
- Date: Sat, 4 Feb 2012 20:15:01 +0100 (CET)
Author: arthur
Date: Sat Feb 4 20:15:00 2012
New Revision: 100
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=100&view=revision
Log:
implement a stdnum.util module for holding utility functions (for now clean())
Added:
python-stdnum/stdnum/util.py
Modified:
python-stdnum/stdnum/br/cpf.py
python-stdnum/stdnum/ean.py
python-stdnum/stdnum/grid.py
python-stdnum/stdnum/iban.py
python-stdnum/stdnum/imei.py
python-stdnum/stdnum/imsi.py
python-stdnum/stdnum/isan.py
python-stdnum/stdnum/isbn.py
python-stdnum/stdnum/ismn.py
python-stdnum/stdnum/issn.py
python-stdnum/stdnum/meid.py
python-stdnum/stdnum/nl/bsn.py
python-stdnum/stdnum/nl/btw.py
python-stdnum/stdnum/nl/onderwijsnummer.py
python-stdnum/stdnum/us/ssn.py
Modified: python-stdnum/stdnum/br/cpf.py
==============================================================================
--- python-stdnum/stdnum/br/cpf.py Sat Feb 4 20:12:20 2012 (r99)
+++ python-stdnum/stdnum/br/cpf.py Sat Feb 4 20:15:00 2012 (r100)
@@ -1,7 +1,7 @@
# cpf.py - functions for handling CPF numbers
# coding: utf-8
#
-# Copyright (C) 2011 Arthur de Jong
+# Copyright (C) 2011, 2012 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
@@ -31,11 +31,13 @@
'231.002.999-00'
"""
+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 number.replace(' ', '').replace('-', '').replace('.', '').strip()
+ return clean(number, ' -.').strip()
def _calc_check_digits(number):
Modified: python-stdnum/stdnum/ean.py
==============================================================================
--- python-stdnum/stdnum/ean.py Sat Feb 4 20:12:20 2012 (r99)
+++ python-stdnum/stdnum/ean.py Sat Feb 4 20:15:00 2012 (r100)
@@ -1,6 +1,6 @@
# ean.py - functions for handling EANs
#
-# Copyright (C) 2011 Arthur de Jong
+# Copyright (C) 2011, 2012 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
@@ -26,11 +26,13 @@
True
"""
+from stdnum.util import clean
+
def compact(number):
"""Convert the EAN to the minimal representation. This strips the number
of any valid separators and removes surrounding whitespace."""
- return number.replace(' ', '').replace('-', '').strip()
+ return clean(number, ' -').strip()
def calc_check_digit(number):
Modified: python-stdnum/stdnum/grid.py
==============================================================================
--- python-stdnum/stdnum/grid.py Sat Feb 4 20:12:20 2012 (r99)
+++ python-stdnum/stdnum/grid.py Sat Feb 4 20:15:00 2012 (r100)
@@ -1,6 +1,6 @@
# grid.py - functions for handling Global Release Identifier (GRid) numbers
#
-# Copyright (C) 2010, 2011 Arthur de Jong
+# Copyright (C) 2010, 2011, 2012 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
@@ -34,11 +34,13 @@
'A1-2425G-ABC1234002-M'
"""
+from stdnum.util import clean
+
def compact(number):
"""Convert the GRid to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
- number = number.replace(' ', '').replace('-', '').strip().upper()
+ number = clean(number, ' -').strip().upper()
if number.startswith('GRID:'):
number = number[5:]
return number
Modified: python-stdnum/stdnum/iban.py
==============================================================================
--- python-stdnum/stdnum/iban.py Sat Feb 4 20:12:20 2012 (r99)
+++ python-stdnum/stdnum/iban.py Sat Feb 4 20:15:00 2012 (r100)
@@ -1,6 +1,6 @@
# iban.py - functions for handling International Bank Account Numbers (IBANs)
#
-# Copyright (C) 2011 Arthur de Jong
+# Copyright (C) 2011, 2012 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
@@ -31,9 +31,11 @@
'GR16 0110 1050 0000 1054 7023 795'
"""
+import re
+
from stdnum import numdb
from stdnum.iso7064 import mod_97_10
-import re
+from stdnum.util import clean
# our open copy of the IBAN database
@@ -49,7 +51,7 @@
def compact(number):
"""Convert the iban number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
- return number.replace(' ', '').replace('-', '').strip().upper()
+ return clean(number, ' -').strip().upper()
def _convert(number):
Modified: python-stdnum/stdnum/imei.py
==============================================================================
--- python-stdnum/stdnum/imei.py Sat Feb 4 20:12:20 2012 (r99)
+++ python-stdnum/stdnum/imei.py Sat Feb 4 20:15:00 2012 (r100)
@@ -1,7 +1,7 @@
# imei.py - functions for handling International Mobile Equipment Identity
# (IMEI) numbers
#
-# Copyright (C) 2010, 2011 Arthur de Jong
+# Copyright (C) 2010, 2011, 2012 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
@@ -37,11 +37,13 @@
('35686800', '004141', '')
"""
+from stdnum.util import clean
+
def compact(number):
"""Convert the IMEI number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
- return number.replace(' ', '').replace('-', '').strip().upper()
+ return clean(number, ' -').strip().upper()
def imei_type(number):
Modified: python-stdnum/stdnum/imsi.py
==============================================================================
--- python-stdnum/stdnum/imsi.py Sat Feb 4 20:12:20 2012 (r99)
+++ python-stdnum/stdnum/imsi.py Sat Feb 4 20:15:00 2012 (r100)
@@ -1,7 +1,7 @@
# imsi.py - functions for handling International Mobile Subscriber Identity
# (IMSI) numbers
#
-# Copyright (C) 2011 Arthur de Jong
+# Copyright (C) 2011, 2012 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
@@ -35,11 +35,13 @@
'China'
"""
+from stdnum.util import clean
+
def compact(number):
"""Convert the IMSI number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
- return number.replace(' ', '').replace('-', '').strip().upper()
+ return clean(number, ' -').strip().upper()
def split(number):
Modified: python-stdnum/stdnum/isan.py
==============================================================================
--- python-stdnum/stdnum/isan.py Sat Feb 4 20:12:20 2012 (r99)
+++ python-stdnum/stdnum/isan.py Sat Feb 4 20:15:00 2012 (r100)
@@ -1,7 +1,7 @@
# isan.py - functions for handling International Standard Audiovisual Numbers
# (ISANs)
#
-# Copyright (C) 2010, 2011 Arthur de Jong
+# Copyright (C) 2010, 2011, 2012 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
@@ -40,13 +40,14 @@
from stdnum.iso7064 import mod_37_36
+from stdnum.util import clean
def split(number):
"""Splits the number into a root, an episode or part, a check digit a
version and another check digit. If any of the parts are missing an
empty string is returned."""
- number = number.replace(' ', '').replace('-', '').strip().upper()
+ number = clean(number, ' -').strip().upper()
if len(number) == 17 or len(number) == 26:
return number[0:12], number[12:16], number[16], number[17:25],
number[25:]
elif len(number) > 16:
Modified: python-stdnum/stdnum/isbn.py
==============================================================================
--- python-stdnum/stdnum/isbn.py Sat Feb 4 20:12:20 2012 (r99)
+++ python-stdnum/stdnum/isbn.py Sat Feb 4 20:15:00 2012 (r100)
@@ -1,6 +1,6 @@
# isbn.py - functions for handling ISBNs
#
-# Copyright (C) 2010, 2011 Arthur de Jong
+# Copyright (C) 2010, 2011, 2012 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
@@ -42,6 +42,7 @@
"""
from stdnum import ean
+from stdnum.util import clean
def compact(number, convert=False):
@@ -49,7 +50,7 @@
of any valid ISBN separators and removes surrounding whitespace. If the
covert parameter is True the number is also converted to ISBN-13
format."""
- number = number.replace(' ', '').replace('-', '').strip().upper()
+ number = clean(number, ' -').strip().upper()
if len(number) == 9:
number = '0' + number
if convert:
Modified: python-stdnum/stdnum/ismn.py
==============================================================================
--- python-stdnum/stdnum/ismn.py Sat Feb 4 20:12:20 2012 (r99)
+++ python-stdnum/stdnum/ismn.py Sat Feb 4 20:15:00 2012 (r100)
@@ -1,6 +1,6 @@
# ismn.py - functions for handling ISMNs
#
-# Copyright (C) 2010, 2011 Arthur de Jong
+# Copyright (C) 2010, 2011, 2012 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
@@ -39,13 +39,13 @@
"""
from stdnum import ean
+from stdnum.util import clean
def compact(number):
"""Convert the ISMN to the minimal representation. This strips the number
of any valid ISMN separators and removes surrounding whitespace."""
- number = number.replace(' ', '').replace('-', '').replace('.', '')
- return number.strip().upper()
+ return clean(number, ' -.').strip().upper()
def ismn_type(number):
Modified: python-stdnum/stdnum/issn.py
==============================================================================
--- python-stdnum/stdnum/issn.py Sat Feb 4 20:12:20 2012 (r99)
+++ python-stdnum/stdnum/issn.py Sat Feb 4 20:15:00 2012 (r100)
@@ -1,6 +1,6 @@
# issn.py - functions for handling ISSNs
#
-# Copyright (C) 2010, 2011 Arthur de Jong
+# Copyright (C) 2010, 2011, 2012 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
@@ -33,12 +33,13 @@
"""
from stdnum import ean
+from stdnum.util import clean
def compact(number):
"""Convert the ISSN to the minimal representation. This strips the number
of any valid ISSN separators and removes surrounding whitespace."""
- return number.replace(' ', '').replace('-', '').strip().upper()
+ return clean(number, ' -').strip().upper()
def _calc_check_digit(number):
Modified: python-stdnum/stdnum/meid.py
==============================================================================
--- python-stdnum/stdnum/meid.py Sat Feb 4 20:12:20 2012 (r99)
+++ python-stdnum/stdnum/meid.py Sat Feb 4 20:15:00 2012 (r100)
@@ -1,6 +1,6 @@
# meid.py - functions for handling Mobile Equipment Identifiers (MEIDs)
#
-# Copyright (C) 2010, 2011 Arthur de Jong
+# Copyright (C) 2010, 2011, 2012 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
@@ -32,13 +32,16 @@
'AF 01 23 45 0A BC DE C'
"""
+from stdnum.util import clean
+
+
_hex_alphabet = '0123456789ABCDEF'
def _cleanup(number):
"""Remove any grouping information from the number and removes surrounding
whitespace."""
- return str(number).replace(' ', '').replace('-', '').strip().upper()
+ return clean(str(number), ' -').strip().upper()
def _ishex(number):
Modified: python-stdnum/stdnum/nl/bsn.py
==============================================================================
--- python-stdnum/stdnum/nl/bsn.py Sat Feb 4 20:12:20 2012 (r99)
+++ python-stdnum/stdnum/nl/bsn.py Sat Feb 4 20:15:00 2012 (r100)
@@ -30,11 +30,13 @@
'1112.22.333'
"""
+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."""
- number = number.replace(' ', '').replace('-', '').replace('.', '').strip()
+ number = clean(number, ' -.').strip()
# pad with leading zeroes
return (9 - len(number)) * '0' + number
Modified: python-stdnum/stdnum/nl/btw.py
==============================================================================
--- python-stdnum/stdnum/nl/btw.py Sat Feb 4 20:12:20 2012 (r99)
+++ python-stdnum/stdnum/nl/btw.py Sat Feb 4 20:15:00 2012 (r100)
@@ -28,12 +28,13 @@
"""
from stdnum.nl import bsn
+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."""
- number = number.replace(' ', '').replace('-', '').replace('.',
'').upper().strip()
+ number = clean(number, ' -.').upper().strip()
if number.startswith('NL'):
number = number[2:]
return bsn.compact(number[:-3]) + number[-3:]
Modified: python-stdnum/stdnum/nl/onderwijsnummer.py
==============================================================================
--- python-stdnum/stdnum/nl/onderwijsnummer.py Sat Feb 4 20:12:20 2012
(r99)
+++ python-stdnum/stdnum/nl/onderwijsnummer.py Sat Feb 4 20:15:00 2012
(r100)
@@ -17,8 +17,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
-"""Module for handling onderwijsnummers (school number), very similar to the
BSN
-(Dutch national identification number) but for students without a BSN.
+"""Module for handling onderwijsnummers (school number), very similar to
+the BSN (Dutch national identification number) but for students without a
+BSN.
>>> is_valid('101222331')
True
Modified: python-stdnum/stdnum/us/ssn.py
==============================================================================
--- python-stdnum/stdnum/us/ssn.py Sat Feb 4 20:12:20 2012 (r99)
+++ python-stdnum/stdnum/us/ssn.py Sat Feb 4 20:15:00 2012 (r100)
@@ -1,6 +1,6 @@
# ssn.py - functions for handling SSNs
#
-# Copyright (C) 2011 Arthur de Jong
+# Copyright (C) 2011, 2012 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
@@ -34,6 +34,9 @@
import re
+from stdnum.util import clean
+
+
# regular expression for matching SSN
_ssn_re =
re.compile('^(?P<area>[0-9]{3})-?(?P<group>[0-9]{2})-?(?P<serial>[0-9]{4})$')
@@ -44,7 +47,7 @@
def compact(number):
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
- return number.replace('-', '').strip()
+ return clean(number, '-').strip()
def is_valid(number):
Added: python-stdnum/stdnum/util.py
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ python-stdnum/stdnum/util.py Sat Feb 4 20:15:00 2012 (r100)
@@ -0,0 +1,29 @@
+# util.py - common utility functions
+#
+# Copyright (C) 2012 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
+
+"""Common functions for other stdnum modules.
+
+>>> clean('123-456:78 9', ' -:')
+'123456789'
+"""
+
+
+def clean(number, deletechars):
+ """Remove the specified characters from the supplied number."""
+ return ''.join(x for x in number if x not in deletechars)
--
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: r100 - in python-stdnum/stdnum: . br nl us,
Commits of the python-stdnum project