[IMP] account_banking: improve resilience against different character sets

This commit is contained in:
Pieter J. Kersten
2011-03-09 13:26:49 +01:00
parent 6a6740cf8f
commit eb423205c1
6 changed files with 15 additions and 7 deletions

View File

@@ -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',

View File

@@ -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')
]

View File

@@ -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',

View File

@@ -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',

View File

@@ -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',

View File

@@ -25,7 +25,7 @@
##############################################################################
{
'name': 'Account Banking',
'version': '0.52',
'version': '0.53',
'license': 'GPL-3',
'author': 'EduSense BV',
'website': 'http://www.edusense.nl',