support unicode keys in dict2attr

This commit is contained in:
Dane Springmeyer 2014-10-24 17:50:40 -07:00
parent 38a169e56e
commit ab451cbee2

View File

@ -35,7 +35,6 @@
#include <mapnik/unicode.hpp>
#include <mapnik/attribute.hpp>
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<std::string>(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<std::string>(keys[i]);
}
object obj = d[key];
if (PyUnicode_Check(obj.ptr()))
{