Skip to content
Myr

Make the _speedups extension compatible with Python 3.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Georg Brandl · committed by Georg Brandl · parent 17f5447 · Browse files · 2 files+41 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+41 added−1 removed

  • other:+41 added−1 removed

2 files+41 added−1 removed

modified:jinja2/_speedups.c+39 added-1 removed
121 unmodified lines
122{123 PyObject *s = NULL, *rv = NULL, *html;124125 /* we don't have to escape integers, bools or floats */126 if (PyInt_CheckExact(text) || PyLong_CheckExact(text) ||126 if (PyLong_CheckExact(text) ||127#if PY_MAJOR_VERSION < 3128 PyInt_CheckExact(text) ||129#endif130 PyFloat_CheckExact(text) || PyBool_Check(text) ||131 text == Py_None)132 return PyObject_CallFunctionObjArgs(markup, text, NULL);133
7 unmodified lines
141142 /* otherwise make the object unicode if it isn't, then escape */143 PyErr_Clear();144 if (!PyUnicode_Check(text)) {145#if PY_MAJOR_VERSION < 3146 PyObject *unicode = PyObject_Unicode(text);147#else148 PyObject *unicode = PyObject_Str(text);149#endif150 if (!unicode)151 return NULL;152 s = escape_unicode((PyUnicodeObject*)unicode);153 Py_DECREF(unicode);
11 unmodified lines
165static PyObject*166soft_unicode(PyObject *self, PyObject *s)167{168 if (!PyUnicode_Check(s))169#if PY_MAJOR_VERSION < 3170 return PyObject_Unicode(s);171#else172 return PyObject_Str(s);173#endif174 Py_INCREF(s);175 return s;176}177
40 unmodified lines
218 {NULL, NULL, 0, NULL} /* Sentinel */219};220221222#if PY_MAJOR_VERSION < 3223224#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */225#define PyMODINIT_FUNC void226#endif227PyMODINIT_FUNC
3 unmodified lines
231 return;232233 Py_InitModule3("jinja2._speedups", module_methods, "");234}235236#else /* Python 3.x module initialization */237238static struct PyModuleDef module_definition = {239 PyModuleDef_HEAD_INIT,240 "jinja2._speedups",241 NULL,242 -1,243 module_methods,244 NULL,245 NULL,246 NULL,247 NULL248};249250PyMODINIT_FUNC251PyInit__speedups(void)252{253 if (!init_constants())254 return NULL;255256 return PyModule_Create(&module_definition);257}258259#endif
modified:CHANGES+2 added
8 unmodified lines
9 pass through a template object if it was passed to it. This10 makes it possible to import or extend from a template object11 that was passed to the template.1213- the _speedups C extension now supports Python 3.1415Version 2.3.116-------------17(bugfix release, released on February 19th 2010)18
141 unmodified lines