diff --git a/genshi/_speedups.c b/genshi/_speedups.c
|
a
|
b
|
|
| 54 | 54 | if (PyObject_TypeCheck(text, &MarkupType)) { |
| 55 | 55 | Py_INCREF(text); |
| 56 | 56 | return text; |
| | 57 | } |
| | 58 | if (PyObject_HasAttrString(text, "__html__")) { |
| | 59 | ret = PyObject_CallMethod(text, "__html__", NULL); |
| | 60 | args = PyTuple_New(1); |
| | 61 | if (args == NULL) { |
| | 62 | Py_DECREF(ret); |
| | 63 | return NULL; |
| | 64 | } |
| | 65 | PyTuple_SET_ITEM(args, 0, ret); |
| | 66 | ret = MarkupType.tp_new(&MarkupType, args, NULL); |
| | 67 | Py_DECREF(args); |
| | 68 | return ret; |
| 57 | 69 | } |
| 58 | 70 | in = (PyUnicodeObject *) PyObject_Unicode(text); |
| 59 | 71 | if (in == NULL) { |
| … |
… |
|
| 183 | 195 | return text; |
| 184 | 196 | } |
| 185 | 197 | return escape(text, quotes); |
| | 198 | } |
| | 199 | |
| | 200 | static PyObject * |
| | 201 | Markup_html(PyObject *self) |
| | 202 | { |
| | 203 | Py_INCREF(self); |
| | 204 | return self; |
| 186 | 205 | } |
| 187 | 206 | |
| 188 | 207 | PyDoc_STRVAR(join__doc__, |
| … |
… |
|
| 513 | 532 | } MarkupObject; |
| 514 | 533 | |
| 515 | 534 | static PyMethodDef Markup_methods[] = { |
| | 535 | {"__html__", (PyCFunction) Markup_html, METH_NOARGS, NULL}, |
| 516 | 536 | {"escape", (PyCFunction) Markup_escape, |
| 517 | 537 | METH_VARARGS|METH_CLASS|METH_KEYWORDS, escape__doc__}, |
| 518 | 538 | {"join", (PyCFunction)Markup_join, METH_VARARGS|METH_KEYWORDS, join__doc__}, |
diff --git a/genshi/builder.py b/genshi/builder.py
|
a
|
b
|
|
| 68 | 68 | Hello, <em>world</em>! |
| 69 | 69 | """ |
| 70 | 70 | |
| 71 | | from genshi.core import Attrs, Namespace, QName, Stream, START, END, TEXT |
| | 71 | from genshi.core import Attrs, Namespace, QName, Stream, START, END, TEXT, \ |
| | 72 | Markup |
| 72 | 73 | |
| 73 | 74 | __all__ = ['Fragment', 'Element', 'ElementFactory', 'tag'] |
| 74 | 75 | __docformat__ = 'restructuredtext en' |
| … |
… |
|
| 105 | 106 | return str(self.generate()) |
| 106 | 107 | |
| 107 | 108 | def __unicode__(self): |
| | 109 | return unicode(self.generate()) |
| | 110 | |
| | 111 | def __html__(self): |
| 108 | 112 | return unicode(self.generate()) |
| 109 | 113 | |
| 110 | 114 | def append(self, node): |
diff --git a/genshi/core.py b/genshi/core.py
|
a
|
b
|
|
| 442 | 442 | def __repr__(self): |
| 443 | 443 | return '<%s %r>' % (self.__class__.__name__, unicode(self)) |
| 444 | 444 | |
| | 445 | def __html__(self): |
| | 446 | return self |
| | 447 | |
| 445 | 448 | def join(self, seq, escape_quotes=True): |
| 446 | 449 | """Return a `Markup` object which is the concatenation of the strings |
| 447 | 450 | in the given sequence, where this `Markup` object is the separator |
| … |
… |
|
| 484 | 487 | return cls() |
| 485 | 488 | if type(text) is cls: |
| 486 | 489 | return text |
| | 490 | if hasattr(text, '__html__'): |
| | 491 | return Markup(text.__html__()) |
| | 492 | |
| 487 | 493 | text = unicode(text).replace('&', '&') \ |
| 488 | 494 | .replace('<', '<') \ |
| 489 | 495 | .replace('>', '>') |
diff --git a/genshi/tests/builder.py b/genshi/tests/builder.py
|
a
|
b
|
|
| 51 | 51 | self.assertEqual((Stream.END, 'b'), xml[3][:2]) |
| 52 | 52 | self.assertEqual((Stream.END, 'span'), xml[4][:2]) |
| 53 | 53 | |
| | 54 | def test_Markup_escape(self): |
| | 55 | from genshi.core import Markup |
| | 56 | m = Markup("See %s") % tag.a("genshi", href='http://genshi.edgwall.org') |
| | 57 | self.assertEqual(m, Markup('See <a href="http://genshi.edgwall.org">' |
| | 58 | 'genshi</a>')) |
| 54 | 59 | |
| 55 | 60 | def suite(): |
| 56 | 61 | suite = unittest.TestSuite() |