1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
--- jinja2/_speedups.c
+++ jinja2/_speedups.c
@@ -123,7 +123,10 @@
PyObject *s = NULL, *rv = NULL, *html;
/* we don't have to escape integers, bools or floats */
- if (PyInt_CheckExact(text) || PyLong_CheckExact(text) ||
+ if (PyLong_CheckExact(text) ||
+#if PY_MAJOR_VERSION < 3
+ PyInt_CheckExact(text) ||
+#endif
PyFloat_CheckExact(text) || PyBool_Check(text) ||
text == Py_None)
return PyObject_CallFunctionObjArgs(markup, text, NULL);
@@ -139,7 +142,11 @@
/* otherwise make the object unicode if it isn't, then escape */
PyErr_Clear();
if (!PyUnicode_Check(text)) {
+#if PY_MAJOR_VERSION >= 3
+ PyObject *unicode = PyObject_Str(text);
+#else
PyObject *unicode = PyObject_Unicode(text);
+#endif
if (!unicode)
return NULL;
s = escape_unicode((PyUnicodeObject*)unicode);
@@ -159,7 +166,11 @@
soft_unicode(PyObject *self, PyObject *s)
{
if (!PyUnicode_Check(s))
+#if PY_MAJOR_VERSION >= 3
+ return PyObject_Str(s);
+#else
return PyObject_Unicode(s);
+#endif
Py_INCREF(s);
return s;
}
@@ -207,15 +218,45 @@
{NULL, NULL, 0, NULL} /* Sentinel */
};
+#if PY_MAJOR_VERSION >= 3
+static struct PyModuleDef module_definition = {
+ PyModuleDef_HEAD_INIT,
+ "jinja2._speedups",
+ NULL,
+ -1,
+ module_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+#endif
+
#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
#define PyMODINIT_FUNC void
#endif
PyMODINIT_FUNC
+#if PY_MAJOR_VERSION >= 3
+PyInit__speedups(void)
+#else
init_speedups(void)
+#endif
{
if (!init_constants())
+#if PY_MAJOR_VERSION >= 3
+ return NULL;
+#else
return;
+#endif
+#if PY_MAJOR_VERSION >= 3
+ PyObject *module = PyModule_Create(&module_definition);
+#else
Py_InitModule3("jinja2._speedups", module_methods, "");
+#endif
+
+#if PY_MAJOR_VERSION >= 3
+ return module;
+#endif
}
|