diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2011-08-19 10:22:13 +0200 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2011-08-19 10:22:13 +0200 |
commit | 881e8a6a2429b43180e1ece0148077bdb77c59d5 (patch) | |
tree | a68cb2dc12bd38f3d73528b9bb7ec705b5fe2093 /stdnum/grid.py | |
parent | 8dbcedd38baa7b04ae66fd4c1908b8eb2dddc613 (diff) |
make source code layout follow PEP8 more
git-svn-id: http://arthurdejong.org/svn/python-stdnum/python-stdnum@76 9dea7c4f-944c-4273-ac1a-574ede026edc
Diffstat (limited to 'stdnum/grid.py')
-rw-r--r-- | stdnum/grid.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/stdnum/grid.py b/stdnum/grid.py index b74807d..852230e 100644 --- a/stdnum/grid.py +++ b/stdnum/grid.py @@ -1,6 +1,6 @@ # grid.py - functions for handling Global Release Identifier (GRid) numbers # -# Copyright (C) 2010 Arthur de Jong +# Copyright (C) 2010, 2011 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,14 +34,16 @@ False 'A1-2425G-ABC1234002-M' """ + 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 = number.replace(' ', '').replace('-', '').strip().upper() if number.startswith('GRID:'): number = number[5:] return number + def is_valid(number): """Checks to see if the number provided is a valid GRid.""" from stdnum.iso7064 import mod_37_36 @@ -51,8 +53,9 @@ def is_valid(number): return False return len(number) == 18 and mod_37_36.is_valid(number) + def format(number, separator='-', add_check_digit=False): """Reformat the passed number to the standard format.""" number = compact(number) - number = ( number[0:2], number[2:7], number[7:17], number[17:] ) + number = (number[0:2], number[2:7], number[7:17], number[17:]) return separator.join(x for x in number if x) |