Browse Source

Make load_entitydefs() work on Python 3.

tags/v0.3
Ben Kurtovic 10 years ago
parent
commit
e02ad8239f
1 changed files with 11 additions and 0 deletions
  1. +11
    -0
      mwparserfromhell/parser/tokenizer.c

+ 11
- 0
mwparserfromhell/parser/tokenizer.c View File

@@ -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;
}


Loading…
Cancel
Save