From 93deeeced8cd3a2fc1138727763306d89af96322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 10 Nov 2014 23:30:49 +0100 Subject: [PATCH] Allow to use easily unicode_literals Transparently encode __name__ to utf-8 to allow usage of unicode_literals Fix PYSON to support unicode issue4294 review11601002 --- trytond/pool.py | 5 ++++- trytond/pyson.py | 16 ++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/trytond/pool.py b/trytond/pool.py index 65c6f49933..6bdceb1add 100644 --- a/trytond/pool.py +++ b/trytond/pool.py @@ -14,7 +14,10 @@ class PoolMeta(type): def __new__(cls, name, bases, dct): new = type.__new__(cls, name, bases, dct) if '__name__' in dct: - new.__name__ = dct['__name__'] + try: + new.__name__ = dct['__name__'] + except TypeError: + new.__name__ = dct['__name__'].encode('utf-8') return new diff --git a/trytond/pyson.py b/trytond/pyson.py index bab351c239..802641e544 100644 --- a/trytond/pyson.py +++ b/trytond/pyson.py @@ -367,9 +367,9 @@ class Get(PYSON): assert isinstance(obj, dict), 'obj must be a dict' self._obj = obj if isinstance(key, PYSON): - assert key.types() == set([str]), 'key must be a string' + assert key.types() == set([str, unicode]), 'key must be a string' else: - assert type(key) == str, 'key must be a string' + assert type(key) in [str, unicode], 'key must be a string' self._key = key self._default = default @@ -397,20 +397,20 @@ class In(PYSON): def __init__(self, key, obj): super(In, self).__init__() if isinstance(key, PYSON): - assert key.types().issubset(set([str, int, long])), \ + assert key.types().issubset(set([str, unicode, int, long])), \ 'key must be a string or an integer or a long' else: - assert type(key) in [str, int, long], \ + assert type(key) in [str, unicode, int, long], \ 'key must be a string or an integer or a long' if isinstance(obj, PYSON): assert obj.types().issubset(set([dict, list])), \ 'obj must be a dict or a list' if obj.types() == set([dict]): - assert type(key) == str, 'key must be a string' + assert type(key) in [str, unicode], 'key must be a string' else: assert type(obj) in [dict, list] if type(obj) == dict: - assert type(key) == str, 'key must be a string' + assert type(key) in [str, unicode], 'key must be a string' self._key = key self._obj = obj @@ -542,10 +542,10 @@ class Len(PYSON): def __init__(self, value): super(Len, self).__init__() if isinstance(value, PYSON): - assert value.types().issubset(set([dict, list, str])), \ + assert value.types().issubset(set([dict, list, str, unicode])), \ 'value must be a dict or a list or a string' else: - assert type(value) in [dict, list, str], \ + assert type(value) in [dict, list, str, unicode], \ 'value must be a dict or list or a string' self._value = value