module documentation
(source)

HTML rendering for twisted.web.
Class CDATA A <![CDATA[]]> block from a template. Given a separate representation in the DOM so that they may be round-tripped through rendering without losing information.
Class ​Char​Ref A numeric character reference. Given a separate representation in the DOM so that non-ASCII characters may be output as pure ASCII.
Class ​Comment A <!-- --> comment from a template. Given a separate representation in the DOM so that they may be round-tripped through rendering without losing information.
Class ​Element Base for classes which can render part of a page.
Class slot Marker for markup insertion in a template.
Class ​Tag No summary
Class ​Tag​Loader An ITemplateLoader that loads existing IRenderable providers.
Class ​XMLFile An ITemplateLoader that loads and parses XML from a file.
Class ​XMLString An ITemplateLoader that loads and parses XML from a string.
Function flatten Incrementally write out a string representation of root using write.
Function flatten​String Collate a string representation of root into a single string.
Function render​Element Render an element or other IRenderable.
Function renderer Decorate with renderer to use methods as template render directives.
Constant NOT​_DONE​_YET Undocumented
Constant TEMPLATE​_NAMESPACE The XML namespace used to identify attributes and elements used by the templating system, which should be removed from the final output document.
Constant VALID​_HTML​_TAG​_NAMES A list of recognized HTML tag names, used by the tag object.
Variable tags A convenience object which can produce Tag objects on demand via attribute access. For example: tags.div is equivalent to Tag("div"). Tags not specified in VALID_HTML_TAG_NAMES will result in an AttributeError.
Class _​NSContext A mapping from XML namespaces onto their prefixes in the document.
Class _​Tag​Factory A factory for Tag objects; the implementation of the tags object.
Class _​To​Stan A SAX parser which converts an XML document to the Twisted STAN Document Object Model.
Function _flatsax​Parse Perform a SAX parse of an XML document with the _ToStan class.
Variable _module​Log Undocumented
def flatten(request, root, write): (source)

Incrementally write out a string representation of root using write.

In order to create a string representation, root will be decomposed into simpler objects which will themselves be decomposed and so on until strings or objects which can easily be converted to strings are encountered.

Parameters
requestA request object which will be passed to the render method of any IRenderable provider which is encountered.
rootAn object to be made flatter. This may be of type unicode, bytes, slot, Tag, tuple, list, types.GeneratorType, Deferred, or something that provides IRenderable.
writeA callable which will be invoked with each bytes produced by flattening root.
Returns
A Deferred which will be called back when root has been completely flattened into write or which will be errbacked if an unexpected exception occurs.
def flattenString(request, root): (source)

Collate a string representation of root into a single string.

This is basically gluing flatten to an io.BytesIO and returning the results. See flatten for the exact meanings of request and root.

Returns
A Deferred which will be called back with a single string as its result when root has been completely flattened into write or which will be errbacked if an unexpected exception occurs.
def renderElement(request, element, doctype=b'<!DOCTYPE html>', _failElement=None): (source)
Render an element or other IRenderable.
Parameters
requestThe Request being rendered to.
elementAn IRenderable which will be rendered.
doctypeA bytes which will be written as the first line of the request, or None to disable writing of a doctype. The string should not include a trailing newline and will default to the HTML5 doctype '<!DOCTYPE html>'.
_fail​ElementUndocumented
Returns
NOT_DONE_YET
Present Since
12.1
@exposer
def renderer(): (source)

Decorate with renderer to use methods as template render directives.

For example:

    class Foo(Element):
        @renderer
        def twiddle(self, request, tag):
            return tag('Hello, world.')

    <div xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1">
        <span t:render="twiddle" />
    </div>

Will result in this final output:

    <div>
        <span>Hello, world.</span>
    </div>
NOT_DONE_YET: int = (source)

Undocumented

Value
1
TEMPLATE_NAMESPACE: str = (source)
The XML namespace used to identify attributes and elements used by the templating system, which should be removed from the final output document.
Value
'http://twistedmatrix.com/ns/twisted.web.template/0.1'
VALID_HTML_TAG_NAMES: set[str] = (source)
A list of recognized HTML tag names, used by the tag object.
Value
set(['a',
     'abbr',
     'acronym',
     'address',
     'applet',
     'area',
     'article',
...
tags = (source)
A convenience object which can produce Tag objects on demand via attribute access. For example: tags.div is equivalent to Tag("div"). Tags not specified in VALID_HTML_TAG_NAMES will result in an AttributeError.
def _flatsaxParse(fl): (source)
Perform a SAX parse of an XML document with the _ToStan class.
Parameters
fl:A file object or filename.The XML document to be parsed.
Returns
a list of Stan objects.
_moduleLog = (source)

Undocumented