From 1f47e10f048a08c3091416641abd974032467a30 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 17 Nov 2012 23:08:53 -0500 Subject: [PATCH] Start some Py3k compatibility stuff. --- mwparserfromhell/parser/__init__.py | 4 +++- mwparserfromhell/parser/builder.c | 24 ------------------------ mwparserfromhell/parser/tokenizer.c | 2 +- mwparserfromhell/parser/tokenizer.h | 4 ++++ setup.py | 6 +++--- 5 files changed, 11 insertions(+), 29 deletions(-) delete mode 100644 mwparserfromhell/parser/builder.c diff --git a/mwparserfromhell/parser/__init__.py b/mwparserfromhell/parser/__init__.py index da24b2f..5baa687 100644 --- a/mwparserfromhell/parser/__init__.py +++ b/mwparserfromhell/parser/__init__.py @@ -28,9 +28,11 @@ joins them together under one interface. try: from ._builder import CBuilder as Builder - from ._tokenizer import CTokenizer as Tokenizer except ImportError: from .builder import Builder +try: + from ._tokenizer import CTokenizer as Tokenizer +except ImportError: from .tokenizer import Tokenizer __all__ = ["Parser"] diff --git a/mwparserfromhell/parser/builder.c b/mwparserfromhell/parser/builder.c deleted file mode 100644 index 7cbe236..0000000 --- a/mwparserfromhell/parser/builder.c +++ /dev/null @@ -1,24 +0,0 @@ -/* -Builder for MWParserFromHell -Copyright (C) 2012 Ben Kurtovic - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#include diff --git a/mwparserfromhell/parser/tokenizer.c b/mwparserfromhell/parser/tokenizer.c index 702e1a3..121ccc9 100644 --- a/mwparserfromhell/parser/tokenizer.c +++ b/mwparserfromhell/parser/tokenizer.c @@ -1394,7 +1394,7 @@ init_tokenizer(void) numdefs = (unsigned) PyList_GET_SIZE(defmap); entitydefs = calloc(numdefs + 1, sizeof(char*)); for (i = 0; i < numdefs; i++) - entitydefs[i] = PyString_AsString(PyList_GET_ITEM(deflist, i)); + entitydefs[i] = PyBytes_AsString(PyList_GET_ITEM(deflist, i)); Py_DECREF(deflist); EMPTY = PyUnicode_FromString(""); diff --git a/mwparserfromhell/parser/tokenizer.h b/mwparserfromhell/parser/tokenizer.h index 2484d4f..dffa0fb 100644 --- a/mwparserfromhell/parser/tokenizer.h +++ b/mwparserfromhell/parser/tokenizer.h @@ -29,6 +29,10 @@ SOFTWARE. #include #include +#if PY_MAJOR_VERSION >= 3 +#define IS_PY3K +#endif + #define malloc PyObject_Malloc #define free PyObject_Free diff --git a/setup.py b/setup.py index e348ce5..cc034e5 100644 --- a/setup.py +++ b/setup.py @@ -28,8 +28,8 @@ from mwparserfromhell import __version__ with open("README.rst") as fp: long_docs = fp.read() -builder = Extension("mwparserfromhell.parser._builder", - sources = ["mwparserfromhell/parser/builder.c"]) +# builder = Extension("mwparserfromhell.parser._builder", +# sources = ["mwparserfromhell/parser/builder.c"]) tokenizer = Extension("mwparserfromhell.parser._tokenizer", sources = ["mwparserfromhell/parser/tokenizer.c"]) @@ -37,7 +37,7 @@ tokenizer = Extension("mwparserfromhell.parser._tokenizer", setup( name = "mwparserfromhell", packages = find_packages(exclude=("tests",)), - ext_modules = [builder, tokenizer], + ext_modules = [tokenizer], test_suite = "tests", version = __version__, author = "Ben Kurtovic",