python 2.6.4 and lower cannot handle unicode keys passed to __init__ (MongoEngine/mongoengine#101)
This commit is contained in:
parent
f108c4288e
commit
0b23bc9cf2
@ -11,7 +11,7 @@ from queryset import DoesNotExist, MultipleObjectsReturned
|
|||||||
from queryset import DO_NOTHING
|
from queryset import DO_NOTHING
|
||||||
|
|
||||||
from mongoengine import signals
|
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)
|
to_str_keys_recursive)
|
||||||
|
|
||||||
import pymongo
|
import pymongo
|
||||||
@ -1054,9 +1054,9 @@ class BaseDocument(object):
|
|||||||
# class if unavailable
|
# class if unavailable
|
||||||
class_name = son.get('_cls', cls._class_name)
|
class_name = son.get('_cls', cls._class_name)
|
||||||
data = dict(("%s" % key, value) for key, value in son.items())
|
data = dict(("%s" % key, value) for key, value in son.items())
|
||||||
if PY25:
|
if not UNICODE_KWARGS:
|
||||||
# PY25 cannot handle unicode keys passed to class constructor
|
# python 2.6.4 and lower cannot handle unicode keys
|
||||||
# example: cls(**data)
|
# passed to class constructor example: cls(**data)
|
||||||
to_str_keys_recursive(data)
|
to_str_keys_recursive(data)
|
||||||
|
|
||||||
if '_types' in data:
|
if '_types' in data:
|
||||||
|
@ -4,6 +4,7 @@ import sys
|
|||||||
|
|
||||||
PY3 = sys.version_info[0] == 3
|
PY3 = sys.version_info[0] == 3
|
||||||
PY25 = sys.version_info[:2] == (2, 5)
|
PY25 = sys.version_info[:2] == (2, 5)
|
||||||
|
UNICODE_KWARGS = int(''.join([str(x) for x in sys.version_info[:3]])) > 264
|
||||||
|
|
||||||
if PY3:
|
if PY3:
|
||||||
import codecs
|
import codecs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user