From ab451cbee287c3f0935d4b3e3a1a1e95ae05f7fa Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Fri, 24 Oct 2014 17:50:40 -0700 Subject: [PATCH] support unicode keys in dict2attr --- bindings/python/python_to_value.hpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/bindings/python/python_to_value.hpp b/bindings/python/python_to_value.hpp index da4830e8a..24c8e5556 100644 --- a/bindings/python/python_to_value.hpp +++ b/bindings/python/python_to_value.hpp @@ -35,7 +35,6 @@ #include #include - namespace mapnik { static mapnik::attributes dict2attr(boost::python::dict const& d) @@ -46,7 +45,26 @@ namespace mapnik { boost::python::list keys=d.keys(); for (int i=0; i < len(keys); ++i) { - std::string key = extract(keys[i]); + std::string key; + object obj_key = keys[i]; + if (PyUnicode_Check(obj_key.ptr())) + { + PyObject* temp = PyUnicode_AsUTF8String(obj_key.ptr()); + if (temp) + { + #if PY_VERSION_HEX >= 0x03000000 + char* c_str = PyBytes_AsString(temp); + #else + char* c_str = PyString_AsString(temp); + #endif + key = c_str; + Py_DecRef(temp); + } + } + else + { + key = extract(keys[i]); + } object obj = d[key]; if (PyUnicode_Check(obj.ptr())) {