From 497a5980d837e212f2444688dce72c6080762280 Mon Sep 17 00:00:00 2001 From: Andrew Udvare Date: Fri, 31 Jan 2014 15:58:35 -0800 Subject: Force all dictionaries keys to be UTF-8 in Python 3 --- cython/plist.pyx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'cython') diff --git a/cython/plist.pyx b/cython/plist.pyx index e08d76a..99b344c 100644 --- a/cython/plist.pyx +++ b/cython/plist.pyx @@ -4,13 +4,7 @@ from libc.stdint cimport * # https://groups.google.com/forum/#!topic/cython-users/xoKNFTRagvk cdef _from_string_and_size(char *s, size_t length): - if PY_MAJOR_VERSION < 3 or s == NULL: - return s[:length] - - if s == NULL: - return s[:length] - else: - return s[:length].decode("ascii") + return s[:length].encode('utf-8') cdef extern from *: ctypedef enum plist_type: @@ -606,7 +600,12 @@ cdef class Dict(Node): plist_dict_next_item(self._c_node, it, &key, &subnode); while subnode is not NULL: - cpython.PyDict_SetItem(self._map, key, plist_t_to_node(subnode, False)) + py_key = key + + if PY_MAJOR_VERSION >= 3: + py_key = py_key.decode('utf-8') + + cpython.PyDict_SetItem(self._map, py_key, plist_t_to_node(subnode, False)) subnode = NULL libc.stdlib.free(key) key = NULL -- cgit v1.1-32-gdbae