j2labs/schematics — pull request #194 by tobigue (2013-12-17 10:25:55+00:00)
Title: Change standard coerce_key function to unicode

Using str() as the standard coerce_key function results in Problems with dictionary keys containing non-ascii characters:

>>> class X(Model):
... d = DictType(BaseType())
...
>>> x = X({"d": {u"äöü": "value"}})
Traceback (most recent call last):
File "", line 1, in
File "/home/tobias/projects/schwaebische/schwaebische-contentpool/eggs/schematics-0.9_4-py2.7.egg/schematics/models.py", line 212, in __init__
mapping=deserialize_mapping)
File "/home/tobias/projects/schwaebische/schwaebische-contentpool/eggs/schematics-0.9_4-py2.7.egg/schematics/models.py", line 252, in convert
return convert(self.__class__, raw_data, **kw)
File "/home/tobias/projects/schwaebische/schwaebische-contentpool/eggs/schematics-0.9_4-py2.7.egg/schematics/transforms.py", line 368, in convert
partial=partial, strict=strict, mapping=mapping)
File "/home/tobias/projects/schwaebische/schwaebische-contentpool/eggs/schematics-0.9_4-py2.7.egg/schematics/transforms.py", line 93, in import_loop
raw_value = field_converter(field, raw_value)
File "/home/tobias/projects/schwaebische/schwaebische-contentpool/eggs/schematics-0.9_4-py2.7.egg/schematics/transforms.py", line 366, in
field_converter = lambda field, value: field.to_native(value)
File "/home/tobias/projects/schwaebische/schwaebische-contentpool/eggs/schematics-0.9_4-py2.7.egg/schematics/types/compound.py", line 247, in to_native
for k, v in value.iteritems())
File "/home/tobias/projects/schwaebische/schwaebische-contentpool/eggs/schematics-0.9_4-py2.7.egg/schematics/types/compound.py", line 247, in
for k, v in value.iteritems())
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)