python 2.6.4 and lower cannot handle unicode keys passed to __init__ (MongoEngine/mongoengine#101)

This commit is contained in:
Ross Lawley 2012-09-03 13:10:06 +01:00
parent f108c4288e
commit 0b23bc9cf2
2 changed files with 5 additions and 4 deletions

View File

@ -11,7 +11,7 @@ from queryset import DoesNotExist, MultipleObjectsReturned
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 @@ class BaseDocument(object):
# 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:

View File

@ -4,6 +4,7 @@ import sys
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