summaryrefslogtreecommitdiffstats
path: root/cython
diff options
context:
space:
mode:
authorGravatar Andrew Udvare2014-01-31 15:58:35 -0800
committerGravatar Nikias Bassen2014-02-11 17:27:12 +0100
commit497a5980d837e212f2444688dce72c6080762280 (patch)
treef2c33f80498b17cf7550ab88031b661cb9d0f6d1 /cython
parent29672075fde96c132d685fad86efafecd0cc5444 (diff)
downloadlibplist-497a5980d837e212f2444688dce72c6080762280.tar.gz
libplist-497a5980d837e212f2444688dce72c6080762280.tar.bz2
Force all dictionaries keys to be UTF-8 in Python 3
Diffstat (limited to 'cython')
-rw-r--r--cython/plist.pyx15
1 files changed, 7 insertions, 8 deletions
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