This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Encode keys properly for Python 3

Change-Id: I6f931788c6d9665bba98083335157318807c6a63
  • Loading branch information...
rtyler committed Mar 22, 2010
1 parent f40427c commit 9fbc54223959c54db001edea62fd5438d43d054a
Showing with 10 additions and 0 deletions.
  1. +10 −0 encoder.c
View
@@ -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);

0 comments on commit 9fbc542

Please sign in to comment.