From b1a9433904e264fcd96bdbfbde0f36af57f569d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 24 Jul 2008 12:54:12 +0200 Subject: [PATCH] Remove encode stuff as we use unicode everywhere --- trytond/ir/translation.py | 4 +--- trytond/ir/ui/view.py | 4 ++-- trytond/osv/fields.py | 28 ++++------------------------ trytond/osv/orm.py | 8 +------- trytond/security.py | 3 --- trytond/tools/convert.py | 28 ++++++++++++++-------------- 6 files changed, 22 insertions(+), 53 deletions(-) diff --git a/trytond/ir/translation.py b/trytond/ir/translation.py index 9ec4035478..d0203af934 100644 --- a/trytond/ir/translation.py +++ b/trytond/ir/translation.py @@ -204,8 +204,6 @@ class Translation(OSV, Cacheable): if source: source = source.strip().replace('\n',' ') - if isinstance(source, unicode): - source = source.encode('utf8') cursor.execute('SELECT value ' \ 'FROM ir_translation ' \ 'WHERE lang=%s ' \ @@ -486,7 +484,7 @@ class ReportTranslationUpdate(Wizard): return strings if node.nodeValue: - txt = node.nodeValue.encode('utf-8').strip() + txt = node.nodeValue.strip() if txt: strings.append(txt) diff --git a/trytond/ir/ui/view.py b/trytond/ir/ui/view.py index c8baec681f..3e26ee4f6d 100644 --- a/trytond/ir/ui/view.py +++ b/trytond/ir/ui/view.py @@ -172,11 +172,11 @@ class View(OSV): if element.get('string'): string = element.get('string') if string: - strings.append(string.encode('utf-8')) + strings.append(string) if element.get('sum'): string = element.get('sum') if string: - strings.append(string.encode('utf-8')) + strings.append(string) for child in element: strings.extend(self._translate_view(child)) return strings diff --git a/trytond/osv/fields.py b/trytond/osv/fields.py index 4dcac3f037..453cfe44f9 100644 --- a/trytond/osv/fields.py +++ b/trytond/osv/fields.py @@ -31,9 +31,11 @@ import sha def _symbol_f(symb): if symb is None or symb == False: return None + elif isinstance(symb, str): + return unicode(symb, 'utf-8') elif isinstance(symb, unicode): - return symb.encode('utf-8') - return str(symb) + return symb + return unicode(symb) class Column(object): _classic_read = True @@ -163,28 +165,6 @@ class Char(Column): def __init__(self, string, size=None, **args): Column.__init__(self, string=string, size=size, **args) - self._symbol_set = (self._symbol_c, self._symbol_set_char) - - def _symbol_set_char(self, symb): - """ - takes a string (encoded in utf8) - and returns a string (encoded in utf8) - """ - #TODO we need to remove the "symb==False" from the next line BUT - #TODO for now too many things rely on this broken behavior - #TODO the 'symb is None' test should be common to all data types - if symb is None or symb == False: - return None - - # 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) - return u_symb.encode('utf8') def sql_type(self): if self.size: diff --git a/trytond/osv/orm.py b/trytond/osv/orm.py index a6fc973ada..4f6321350e 100644 --- a/trytond/osv/orm.py +++ b/trytond/osv/orm.py @@ -2587,13 +2587,7 @@ class ORM(object): else: add_null = False if arg[1] in ('like', 'ilike'): - if isinstance(arg[2], str): - str_utf8 = arg[2] - elif isinstance(arg[2], unicode): - str_utf8 = arg[2].encode('utf-8') - else: - str_utf8 = str(arg[2]) - qu2.append('%%%s%%' % str_utf8) + qu2.append('%%%s%%' % arg[2]) if not str_utf8: add_null = True else: diff --git a/trytond/security.py b/trytond/security.py index 8b338805ad..654f4c4c73 100644 --- a/trytond/security.py +++ b/trytond/security.py @@ -10,8 +10,6 @@ SESSION_TIMEOUT = 600 #seconds _USER_CACHE = {} def login(dbname, loginname, password, cache=True): - loginname = loginname.encode('utf-8') - password = password.encode('utf-8') cursor = pooler.get_db(dbname).cursor() password_sha = sha.new(password).hexdigest() cursor.execute('SELECT id FROM res_user ' @@ -40,7 +38,6 @@ def check_super(passwd): raise Exception('AccessDenied') def check(dbname, user, session, outdate_timeout=True): - session = session.encode('utf-8') result = False if _USER_CACHE.get(dbname, {}).has_key(user): to_del = [] diff --git a/trytond/tools/convert.py b/trytond/tools/convert.py index 59c7a1697f..da981ff4c8 100644 --- a/trytond/tools/convert.py +++ b/trytond/tools/convert.py @@ -48,11 +48,11 @@ class MenuitemTagHandler: values = {} - self.xml_id = attributes['id'].encode('utf8') + self.xml_id = attributes['id'] for attr in ('name', 'icon', 'sequence', 'parent', 'action', 'groups'): if attributes.get(attr): - values[attr] = attributes.get(attr).encode('utf8') + values[attr] = attributes.get(attr) if values.get('parent'): @@ -83,7 +83,7 @@ class MenuitemTagHandler: values['action'] = '%s,%s' % (action_type, action_id) - icon = attributes.get('icon', '').encode('utf8') + icon = attributes.get('icon', '') if icon: values['icon'] = icon elif action_type == 'ir.action.wizard': @@ -160,12 +160,12 @@ class RecordTagHandler: # Manage the top level tag if name == "record": - self.model = self.mh.pool.get(attributes["model"].encode('utf8')) + self.model = self.mh.pool.get(attributes["model"]) assert self.model, "The model %s does not exist !" % \ - (attributes["model"].encode('utf8'),) + (attributes["model"],) - self.xml_id = attributes["id"].encode('utf8') - self.update = bool(int(attributes.get('update', '0').encode('utf8'))) + self.xml_id = attributes["id"] + self.update = bool(int(attributes.get('update', '0'))) # create/update a dict containing fields values self.values = {} @@ -178,8 +178,8 @@ class RecordTagHandler: # Manage included tags: elif name == "field": - field_name = attributes['name'].encode('utf8') - field_type = attributes.get('type', '').encode('utf8') + field_name = attributes['name'] + field_type = attributes.get('type', '') # Create a new entry in the values self.values[field_name] = "" # Remind the current name (see characters) @@ -189,13 +189,13 @@ class RecordTagHandler: self.cdata = "start" # Catch the known attributes - search_attr = attributes.get('search','').encode('utf8') - ref_attr = attributes.get('ref', '').encode('utf8') - eval_attr = attributes.get('eval', '').encode('utf8') + search_attr = attributes.get('search','') + ref_attr = attributes.get('ref', '') + eval_attr = attributes.get('eval', '') if search_attr: if attributes.get('model', ''): - search_model = attributes['model'].encode('utf8') + search_model = attributes['model'] else: search_model = self.model._columns[field_name]._obj f_obj = self.mh.pool.get(search_model) @@ -237,7 +237,7 @@ class RecordTagHandler: data = CDATA_START.sub('', data) self.start_cdata = "inside" - self.values[self.current_field] += data.encode('utf8') + self.values[self.current_field] += data def endElement(self, name):