From 881e8a6a2429b43180e1ece0148077bdb77c59d5 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Fri, 19 Aug 2011 08:22:13 +0000 Subject: make source code layout follow PEP8 more git-svn-id: http://arthurdejong.org/svn/python-stdnum/python-stdnum@76 9dea7c4f-944c-4273-ac1a-574ede026edc --- getiban.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'getiban.py') diff --git a/getiban.py b/getiban.py index 287c082..de18728 100755 --- a/getiban.py +++ b/getiban.py @@ -30,22 +30,26 @@ import re # The place where the current version of IBAN_Registry.txt can be downloaded. download_url = 'http://www.swift.com/dsp/resources/documents/IBAN_Registry.txt' + def splitlines(f): """Read lines from the TAB-delimited IBAN_Registry.txt file and return a dictionary per read line. We clean up the values a bit because it contains some junk.""" stripit = ' \t\n\r;:\'"' - firstline = [ x.strip(stripit) for x in f.readline().lower().split('\t') ] + firstline = [x.strip(stripit) for x in f.readline().lower().split('\t')] for line in f: - yield dict(zip(firstline, [ x.strip(stripit) for x in line.split('\t') ])) + yield dict(zip(firstline, [x.strip(stripit) + for x in line.split('\t')])) + def get_country_codes(line): """Return the list of country codes this line has.""" # simplest case first if len(line['country code as defined in iso 3166']) == 2: - return [ line['country code as defined in iso 3166'] ] + return [line['country code as defined in iso 3166']] # fall back to parsing the IBAN structure - return [ x.strip()[:2] for x in line['iban structure'].split(',') ] + return [x.strip()[:2] for x in line['iban structure'].split(',')] + def parse(f): """Parse the specified file.""" @@ -54,11 +58,14 @@ def parse(f): for line in splitlines(f): for cc in get_country_codes(line): # print country line - print '%s country="%s" bban="%s"' % ( cc, line['name of country'], line['bban structure']) + print '%s country="%s" bban="%s"' % ( + cc, line['name of country'], line['bban structure']) # TODO: some countries have a fixed check digit value # TODO: some countries have extra check digits # TODO: use "Bank identifier position within the BBAN" field - # to add labels to the ranges (Bank identifier and Branch Identifier) + # to add labels to the ranges (Bank identifier and Branch + # Identifier) + if __name__ == '__main__': #f = open('IBAN_Registry.txt', 'r') -- cgit v1.2.3