diff --git a/bin/osv/fields.py b/bin/osv/fields.py index 99b39ed9c65d42d9181ec42e0cbedb265ca9038e..b44579957c465c6b7cb6a1f77bd7d81921d6523a 100644 --- a/bin/osv/fields.py +++ b/bin/osv/fields.py @@ -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') diff --git a/bin/tools/misc.py b/bin/tools/misc.py index 4389ee588e0fbe9ebdddc4afa3db916d17c05562..5eee773f0f12ade51d3f5b7d4c555811002180b7 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -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'):