From e02ad8239f16d78e216e8f809ee162c8213e2287 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Thu, 15 Aug 2013 00:11:42 -0400 Subject: [PATCH] Make load_entitydefs() work on Python 3. --- mwparserfromhell/parser/tokenizer.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mwparserfromhell/parser/tokenizer.c b/mwparserfromhell/parser/tokenizer.c index 60223e1..b3ad3ec 100644 --- a/mwparserfromhell/parser/tokenizer.c +++ b/mwparserfromhell/parser/tokenizer.c @@ -2307,6 +2307,9 @@ static int load_entitydefs(void) { PyObject *tempmod, *defmap, *deflist; unsigned numdefs, i; +#ifdef IS_PY3K + PyObject *string; +#endif #ifdef IS_PY3K tempmod = PyImport_ImportModule("html.entities"); @@ -2328,7 +2331,15 @@ static int load_entitydefs(void) if (!entitydefs) return -1; for (i = 0; i < numdefs; i++) { +#ifdef IS_PY3K + string = PyUnicode_AsASCIIString(PyList_GET_ITEM(deflist, i)); + if (!string) + return -1; + entitydefs[i] = PyBytes_AsString(string); + Py_DECREF(string); +#else entitydefs[i] = PyBytes_AsString(PyList_GET_ITEM(deflist, i)); +#endif if (!entitydefs[i]) return -1; }