Edgewall Software

Ticket #202: ticket202.diff

File ticket202.diff, 2.2 KB (added by cmlenz, 8 years ago)

Patch

  • genshi/core.py

     
    444444    def __repr__(self):
    445445        return '<%s %r>' % (self.__class__.__name__, unicode(self))
    446446
     447    def __html__(self):
     448        return self
     449
    447450    def join(self, seq, escape_quotes=True):
    448451        """Return a `Markup` object which is the concatenation of the strings
    449452        in the given sequence, where this `Markup` object is the separator
     
    486489            return cls()
    487490        if type(text) is cls:
    488491            return text
     492        if hasattr(text, '__html__'):
     493            return Markup(text.__html__())
     494
    489495        text = unicode(text).replace('&', '&amp;') \
    490496                            .replace('<', '&lt;') \
    491497                            .replace('>', '&gt;')
  • genshi/_speedups.c

     
    5555        Py_INCREF(text);
    5656        return text;
    5757    }
     58    if (PyObject_HasAttrString(text, "__html__")) {
     59        ret = PyObject_CallMethod(text, "__html__", NULL);
     60        Py_INCREF(ret);
     61        args = PyTuple_New(1);
     62        if (args == NULL) {
     63            Py_DECREF(ret);
     64            return NULL;
     65        }
     66        PyTuple_SET_ITEM(args, 0, ret);
     67        ret = MarkupType.tp_new(&MarkupType, args, NULL);
     68        Py_DECREF(args);
     69        return ret;
     70    }
    5871    in = (PyUnicodeObject *) PyObject_Unicode(text);
    5972    if (in == NULL) {
    6073        return NULL;
     
    184197    return self;
    185198}
    186199
     200static PyObject *
     201Markup_html(PyObject *self)
     202{
     203    Py_INCREF(self);
     204    return self;
     205}
     206
    187207PyDoc_STRVAR(escape__doc__,
    188208"Create a Markup instance from a string and escape special characters\n\
    189209it may contain (<, >, & and \").\n\
     
    521541} MarkupObject;
    522542
    523543static PyMethodDef Markup_methods[] = {
     544    {"__html__", (PyCFunction) Markup_html, METH_NOARGS, NULL},
    524545    {"escape", (PyCFunction) Markup_escape,
    525546     METH_VARARGS|METH_CLASS|METH_KEYWORDS, escape__doc__},
    526547    {"join", (PyCFunction)Markup_join, METH_VARARGS|METH_KEYWORDS, join__doc__},