diff --git a/mongoengine/base.py b/mongoengine/base.py index 82f79d3b2..dc7ef8a08 100644 --- a/mongoengine/base.py +++ b/mongoengine/base.py @@ -11,7 +11,7 @@ from queryset import DO_NOTHING from mongoengine import signals -from mongoengine.python_support import (PY3, PY25, txt_type, +from mongoengine.python_support import (PY3, UNICODE_KWARGS, txt_type, to_str_keys_recursive) import pymongo @@ -1054,9 +1054,9 @@ def _from_son(cls, son): # class if unavailable class_name = son.get('_cls', cls._class_name) data = dict(("%s" % key, value) for key, value in son.items()) - if PY25: - # PY25 cannot handle unicode keys passed to class constructor - # example: cls(**data) + if not UNICODE_KWARGS: + # python 2.6.4 and lower cannot handle unicode keys + # passed to class constructor example: cls(**data) to_str_keys_recursive(data) if '_types' in data: diff --git a/mongoengine/python_support.py b/mongoengine/python_support.py index 02dc28619..097740eb1 100644 --- a/mongoengine/python_support.py +++ b/mongoengine/python_support.py @@ -4,6 +4,7 @@ PY3 = sys.version_info[0] == 3 PY25 = sys.version_info[:2] == (2, 5) +UNICODE_KWARGS = int(''.join([str(x) for x in sys.version_info[:3]])) > 264 if PY3: import codecs