[IMP] rewrote the translation tbale lookup without downgrading strings to latin-1

bzr revid: ls@numerigraphe.fr-20111121153539-a060b20nvvf6x2c7
This commit is contained in:
Numerigraphe - Lionel Sausin 2011-11-21 16:35:39 +01:00
parent c8152fd397
commit ddb1ec724f
1 changed files with 4 additions and 11 deletions

View File

@ -19,9 +19,6 @@
# #
############################################################################## ##############################################################################
import string
import unicodedata
import netsvc import netsvc
from osv import fields, osv from osv import fields, osv
from tools.translate import _ from tools.translate import _
@ -48,14 +45,10 @@ class res_partner_bank(osv.osv):
bank_acc.acc_number) bank_acc.acc_number)
# Translate letters into numbers according to a specific table # Translate letters into numbers according to a specific table
# (notice how s -> 2) # (notice how s -> 2)
# Note: maketrans and translate work best with latin1 - that table = dict((ord(a), b) for a, b in zip(
# should not be a problem for RIB data u'abcdefghijklmnopqrstuvwxyz', u'12345678912345678923456789'))
# XXX use dict((ord(a), b) for a, b in zip(intab, outtab)) rib = rib.lower().translate(table)
# and translate() # compute the key
rib = rib.lower().encode('latin-1').translate(
string.maketrans(u'abcdefghijklmnopqrstuvwxyz',
u'12345678912345678923456789'))
# compute the key
key = 97 - (100 * int(rib)) % 97 key = 97 - (100 * int(rib)) % 97
if int(bank_acc.key) != key: if int(bank_acc.key) != key:
return False return False