From eb423205c1319ecc7d3294624c559a08c8ac9efe Mon Sep 17 00:00:00 2001 From: "Pieter J. Kersten" Date: Wed, 9 Mar 2011 13:26:49 +0100 Subject: [PATCH] [IMP] account_banking: improve resilience against different character sets --- account_banking/__terp__.py | 2 +- account_banking/parsers/convert.py | 12 ++++++++++-- account_banking_fi_patu/__terp__.py | 2 +- account_banking_nl_clieop/__terp__.py | 2 +- account_banking_nl_girotel/__terp__.py | 2 +- account_banking_nl_multibank/__terp__.py | 2 +- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/account_banking/__terp__.py b/account_banking/__terp__.py index 4b0c68dff..913b363c2 100644 --- a/account_banking/__terp__.py +++ b/account_banking/__terp__.py @@ -25,7 +25,7 @@ ############################################################################## { 'name': 'Account Banking', - 'version': '0.1.52', + 'version': '0.1.53', 'license': 'GPL-3', 'author': 'EduSense BV', 'website': 'http://www.edusense.nl', diff --git a/account_banking/parsers/convert.py b/account_banking/parsers/convert.py index 064507110..326fc8813 100644 --- a/account_banking/parsers/convert.py +++ b/account_banking/parsers/convert.py @@ -46,12 +46,20 @@ def date2date(datestr, fromfmt='%d/%m/%y', tofmt='%Y-%m-%d'): _SWIFT = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-?:().,'+ " -def to_swift(astr): +def to_swift(astr, schemes=['utf-8', 'latin-1', 'ascii']): ''' Reduce a string to SWIFT format ''' if not isinstance(astr, unicode): - astr = unicode(astr, 'utf-8') + for scheme in schemes: + try: + astr = unicode(astr, scheme) + break + except UnicodeDecodeError: + pass + if not isinstance(astr, unicode): + return astr + s = [x in _SWIFT and x or ' ' for x in unicodedata.normalize('NFKD', astr).encode('ascii', 'ignore') ] diff --git a/account_banking_fi_patu/__terp__.py b/account_banking_fi_patu/__terp__.py index e365fb2da..8ba0c0363 100644 --- a/account_banking_fi_patu/__terp__.py +++ b/account_banking_fi_patu/__terp__.py @@ -26,7 +26,7 @@ ############################################################################## { 'name': 'Account Banking PATU module', - 'version': '0.52', + 'version': '0.53', 'license': 'GPL-3', 'author': 'Sami Haahtinen', 'website': 'http://ressukka.net', diff --git a/account_banking_nl_clieop/__terp__.py b/account_banking_nl_clieop/__terp__.py index a341b0b92..cc279b66e 100644 --- a/account_banking_nl_clieop/__terp__.py +++ b/account_banking_nl_clieop/__terp__.py @@ -25,7 +25,7 @@ ############################################################################## { 'name': 'Account Banking NL ClieOp', - 'version': '0.52', + 'version': '0.53', 'license': 'GPL-3', 'author': 'EduSense BV', 'website': 'http://www.edusense.nl', diff --git a/account_banking_nl_girotel/__terp__.py b/account_banking_nl_girotel/__terp__.py index 8e25217d3..64c4e641c 100644 --- a/account_banking_nl_girotel/__terp__.py +++ b/account_banking_nl_girotel/__terp__.py @@ -25,7 +25,7 @@ ############################################################################## { 'name': 'Account Banking - Girotel', - 'version': '0.52', + 'version': '0.53', 'license': 'GPL-3', 'author': 'EduSense BV', 'website': 'http://www.edusense.nl', diff --git a/account_banking_nl_multibank/__terp__.py b/account_banking_nl_multibank/__terp__.py index e52689fb9..cc2dcda67 100644 --- a/account_banking_nl_multibank/__terp__.py +++ b/account_banking_nl_multibank/__terp__.py @@ -25,7 +25,7 @@ ############################################################################## { 'name': 'Account Banking', - 'version': '0.52', + 'version': '0.53', 'license': 'GPL-3', 'author': 'EduSense BV', 'website': 'http://www.edusense.nl',