瀏覽代碼

Make load_entitydefs() work on Python 3.

tags/v0.3
Ben Kurtovic 11 年之前
父節點
當前提交
e02ad8239f
共有 1 個檔案被更改,包括 11 行新增0 行删除
  1. +11
    -0
      mwparserfromhell/parser/tokenizer.c

+ 11
- 0
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;
}


Loading…
取消
儲存