Skip to content

Commit

Permalink
Use interned '__html__'
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Apr 27, 2018
1 parent 6ce4a35 commit f5718d7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion markupsafe/_speedups.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,20 @@ escape_unicode(PyUnicodeObject *in)
static PyObject*
escape(PyObject *self, PyObject *text)
{
static PyObject *id_html;
PyObject *s = NULL, *rv = NULL, *html;

if (id_html == NULL) {
#if PY_MAJOR_VERSION < 3
id_html = PyString_InternFromString("__html__");
#else
id_html = PyUnicode_InternFromString("__html__");
#endif
if (id_html == NULL) {
return NULL;
}
}

/* we don't have to escape integers, bools or floats */
if (PyLong_CheckExact(text) ||
#if PY_MAJOR_VERSION < 3
Expand All @@ -296,7 +308,7 @@ escape(PyObject *self, PyObject *text)
return PyObject_CallFunctionObjArgs(markup, text, NULL);

/* if the object has an __html__ method that performs the escaping */
html = PyObject_GetAttrString(text, "__html__");
html = PyObject_GetAttr(text ,id_html);
if (html) {
s = PyObject_CallObject(html, NULL);
Py_DECREF(html);
Expand Down

0 comments on commit f5718d7

Please sign in to comment.