Encode keys properly for Python 3

Change-Id: I6f931788c6d9665bba98083335157318807c6a63
This commit is contained in:
R. Tyler Ballance 2010-03-22 16:03:19 -07:00
parent f40427c52c
commit 9fbc542239
1 changed files with 10 additions and 0 deletions

View File

@ -133,7 +133,17 @@ static yajl_gen_status ProcessObject(_YajlEncoder *self, PyObject *object)
(PyInt_Check(key)) ||
#endif
(PyLong_Check(key)) ) {
/*
* Performing the conversion separately for Python 2
* and Python 3 to ensure we consistently generate
* unicode strings in both versions
*/
#ifdef IS_PYTHON3
newKey = PyObject_Str(key);
#else
newKey = PyObject_Unicode(key);
#endif
}
status = ProcessObject(self, newKey);