comparison genshi/output.py @ 425:073640758a42 trunk

Try to use proper reStructuredText for docstrings throughout.
author cmlenz
date Thu, 22 Mar 2007 12:45:18 +0000
parents bd51adc20a67
children 821fc97d3c0a
comparison
equal deleted inserted replaced
424:11355f9db50c 425:073640758a42
26 from genshi.core import DOCTYPE, START, END, START_NS, END_NS, TEXT, \ 26 from genshi.core import DOCTYPE, START, END, START_NS, END_NS, TEXT, \
27 START_CDATA, END_CDATA, PI, COMMENT, XML_NAMESPACE 27 START_CDATA, END_CDATA, PI, COMMENT, XML_NAMESPACE
28 28
29 __all__ = ['DocType', 'XMLSerializer', 'XHTMLSerializer', 'HTMLSerializer', 29 __all__ = ['DocType', 'XMLSerializer', 'XHTMLSerializer', 'HTMLSerializer',
30 'TextSerializer'] 30 'TextSerializer']
31 __docformat__ = 'restructuredtext en'
31 32
32 33
33 class DocType(object): 34 class DocType(object):
34 """Defines a number of commonly used DOCTYPE declarations as constants.""" 35 """Defines a number of commonly used DOCTYPE declarations as constants."""
35 36
67 68
68 def __init__(self, doctype=None, strip_whitespace=True, 69 def __init__(self, doctype=None, strip_whitespace=True,
69 namespace_prefixes=None): 70 namespace_prefixes=None):
70 """Initialize the XML serializer. 71 """Initialize the XML serializer.
71 72
72 @param doctype: a `(name, pubid, sysid)` tuple that represents the 73 :param doctype: a ``(name, pubid, sysid)`` tuple that represents the
73 DOCTYPE declaration that should be included at the top of the 74 DOCTYPE declaration that should be included at the top
74 generated output 75 of the generated output
75 @param strip_whitespace: whether extraneous whitespace should be 76 :param strip_whitespace: whether extraneous whitespace should be
76 stripped from the output 77 stripped from the output
77 """ 78 """
78 self.preamble = [] 79 self.preamble = []
79 if doctype: 80 if doctype:
80 self.preamble.append((DOCTYPE, doctype, (None, -1, -1))) 81 self.preamble.append((DOCTYPE, doctype, (None, -1, -1)))
81 self.filters = [EmptyTagFilter()] 82 self.filters = [EmptyTagFilter()]
246 ]) 247 ])
247 248
248 def __init__(self, doctype=None, strip_whitespace=True): 249 def __init__(self, doctype=None, strip_whitespace=True):
249 """Initialize the HTML serializer. 250 """Initialize the HTML serializer.
250 251
251 @param doctype: a `(name, pubid, sysid)` tuple that represents the 252 :param doctype: a ``(name, pubid, sysid)`` tuple that represents the
252 DOCTYPE declaration that should be included at the top of the 253 DOCTYPE declaration that should be included at the top
253 generated output 254 of the generated output
254 @param strip_whitespace: whether extraneous whitespace should be 255 :param strip_whitespace: whether extraneous whitespace should be
255 stripped from the output 256 stripped from the output
256 """ 257 """
257 super(HTMLSerializer, self).__init__(doctype, False) 258 super(HTMLSerializer, self).__init__(doctype, False)
258 self.filters = [EmptyTagFilter()] 259 self.filters = [EmptyTagFilter()]
259 if strip_whitespace: 260 if strip_whitespace:
260 self.filters.append(WhitespaceFilter(self._PRESERVE_SPACE, 261 self.filters.append(WhitespaceFilter(self._PRESERVE_SPACE,
379 380
380 class NamespaceFlattener(object): 381 class NamespaceFlattener(object):
381 r"""Output stream filter that removes namespace information from the stream, 382 r"""Output stream filter that removes namespace information from the stream,
382 instead adding namespace attributes and prefixes as needed. 383 instead adding namespace attributes and prefixes as needed.
383 384
384 @param prefixes: optional mapping of namespace URIs to prefixes 385 :param prefixes: optional mapping of namespace URIs to prefixes
385 386
386 >>> from genshi.input import XML 387 >>> from genshi.input import XML
387 >>> xml = XML('''<doc xmlns="NS1" xmlns:two="NS2"> 388 >>> xml = XML('''<doc xmlns="NS1" xmlns:two="NS2">
388 ... <two:item/> 389 ... <two:item/>
389 ... </doc>''') 390 ... </doc>''')
490 491
491 class NamespaceStripper(object): 492 class NamespaceStripper(object):
492 r"""Stream filter that removes all namespace information from a stream, and 493 r"""Stream filter that removes all namespace information from a stream, and
493 optionally strips out all tags not in a given namespace. 494 optionally strips out all tags not in a given namespace.
494 495
495 @param namespace: the URI of the namespace that should not be stripped. If 496 :param namespace: the URI of the namespace that should not be stripped. If
496 not set, only elements with no namespace are included in the output. 497 not set, only elements with no namespace are included in
498 the output.
497 499
498 >>> from genshi.input import XML 500 >>> from genshi.input import XML
499 >>> xml = XML('''<doc xmlns="NS1" xmlns:two="NS2"> 501 >>> xml = XML('''<doc xmlns="NS1" xmlns:two="NS2">
500 ... <two:item/> 502 ... <two:item/>
501 ... </doc>''') 503 ... </doc>''')
547 """ 549 """
548 550
549 def __init__(self, preserve=None, noescape=None): 551 def __init__(self, preserve=None, noescape=None):
550 """Initialize the filter. 552 """Initialize the filter.
551 553
552 @param preserve: a set or sequence of tag names for which white-space 554 :param preserve: a set or sequence of tag names for which white-space
553 should be preserved 555 should be preserved
554 @param noescape: a set or sequence of tag names for which text content 556 :param noescape: a set or sequence of tag names for which text content
555 should not be escaped 557 should not be escaped
556 558
557 The `noescape` set is expected to refer to elements that cannot contain 559 The `noescape` set is expected to refer to elements that cannot contain
558 further child elements (such as <style> or <script> in HTML documents). 560 further child elements (such as ``<style>`` or ``<script>`` in HTML
561 documents).
559 """ 562 """
560 if preserve is None: 563 if preserve is None:
561 preserve = [] 564 preserve = []
562 self.preserve = frozenset(preserve) 565 self.preserve = frozenset(preserve)
563 if noescape is None: 566 if noescape is None:
Copyright (C) 2012-2017 Edgewall Software