[FIX] unicode proble.
lp bug: https://launchpad.net/bugs/327294 fixed bzr revid: ame@tinyerp.com-20090212133252-wludmq0d95irp6dm
This commit is contained in:
parent
86fad5a90e
commit
b850cfe3e5
|
@ -155,12 +155,8 @@ class char(_column):
|
|||
|
||||
# we need to convert the string to a unicode object to be able
|
||||
# to evaluate its length (and possibly truncate it) reliably
|
||||
if isinstance(symb, str):
|
||||
u_symb = unicode(symb, 'utf8')
|
||||
elif isinstance(symb, unicode):
|
||||
u_symb = symb
|
||||
else:
|
||||
u_symb = unicode(symb)
|
||||
u_symb = tools.ustr(symb)
|
||||
|
||||
return u_symb[:self.size].encode('utf8')
|
||||
|
||||
|
||||
|
|
|
@ -677,11 +677,19 @@ def ustr(value):
|
|||
if not isinstance(value, str):
|
||||
value = str(value)
|
||||
|
||||
try:
|
||||
try: # first try utf-8
|
||||
return unicode(value, 'utf-8')
|
||||
except:
|
||||
from locale import getlocale
|
||||
return unicode(value, getlocale()[1])
|
||||
pass
|
||||
|
||||
try: # then extened iso-8858
|
||||
return unicode(value, 'iso-8859-15')
|
||||
except:
|
||||
pass
|
||||
|
||||
# else use default system locale
|
||||
from locale import getlocale
|
||||
return unicode(value, getlocale()[1])
|
||||
|
||||
def exception_to_unicode(e):
|
||||
if hasattr(e, 'message'):
|
||||
|
|
Loading…
Reference in New Issue