comparison markup/output.py @ 105:334a338847af

Include processing instructions in serialized streams.
author cmlenz
date Fri, 28 Jul 2006 15:15:50 +0000
parents 35d681a94763
children 2de3f9d84a1c
comparison
equal deleted inserted replaced
104:e9259920db05 105:334a338847af
20 except NameError: 20 except NameError:
21 from sets import ImmutableSet as frozenset 21 from sets import ImmutableSet as frozenset
22 from itertools import chain 22 from itertools import chain
23 23
24 from markup.core import escape, Markup, Namespace, QName 24 from markup.core import escape, Markup, Namespace, QName
25 from markup.core import DOCTYPE, START, END, START_NS, END_NS, TEXT, COMMENT 25 from markup.core import DOCTYPE, START, END, START_NS, END_NS, TEXT, COMMENT, PI
26 26
27 __all__ = ['Serializer', 'XMLSerializer', 'HTMLSerializer'] 27 __all__ = ['Serializer', 'XMLSerializer', 'HTMLSerializer']
28 28
29 29
30 class Serializer(object): 30 class Serializer(object):
152 yield escape(data, quotes=False) 152 yield escape(data, quotes=False)
153 153
154 elif kind is COMMENT: 154 elif kind is COMMENT:
155 yield Markup('<!--%s-->' % data) 155 yield Markup('<!--%s-->' % data)
156 156
157 elif kind is PI:
158 yield Markup('<?%s %s?>' % data)
159
157 160
158 class XHTMLSerializer(XMLSerializer): 161 class XHTMLSerializer(XMLSerializer):
159 """Produces XHTML text from an event stream. 162 """Produces XHTML text from an event stream.
160 163
161 >>> from markup.builder import tag 164 >>> from markup.builder import tag
236 yield escape(data, quotes=False) 239 yield escape(data, quotes=False)
237 240
238 elif kind is COMMENT: 241 elif kind is COMMENT:
239 yield Markup('<!--%s-->' % data) 242 yield Markup('<!--%s-->' % data)
240 243
244 elif kind is PI:
245 yield Markup('<?%s %s?>' % data)
246
241 247
242 class HTMLSerializer(XHTMLSerializer): 248 class HTMLSerializer(XHTMLSerializer):
243 """Produces HTML text from an event stream. 249 """Produces HTML text from an event stream.
244 250
245 >>> from markup.builder import tag 251 >>> from markup.builder import tag
306 yield escape(data, quotes=False) 312 yield escape(data, quotes=False)
307 313
308 elif kind is COMMENT: 314 elif kind is COMMENT:
309 yield Markup('<!--%s-->' % data) 315 yield Markup('<!--%s-->' % data)
310 316
317 elif kind is PI:
318 yield Markup('<?%s %s?>' % data)
319
311 320
312 class _PushbackIterator(object): 321 class _PushbackIterator(object):
313 """A simple wrapper for iterators that allows pushing items back on the 322 """A simple wrapper for iterators that allows pushing items back on the
314 queue via the `pushback()` method. 323 queue via the `pushback()` method.
315 324
Copyright (C) 2012-2017 Edgewall Software