Go to the latest version of this document.
search in docstrings

Search bar offers the following options:

- Term presence. The below example searches for documents that must contain “foo”, might contain “bar” and must not contain “baz”: `+foo bar -baz`
- Wildcards. The below example searches for documents with words beginning with “foo”: `foo*`
- Search in specific fields. The following search matches all objects in "twisted.mail" that matches “search”: `+qname:twisted.mail.* +search`

  Possible fields: 'name', 'qname' (fully qualified name), 'docstring', and 'kind'. Last two fields are only applicable if "search in docstrings" is enabled.

- Fuzzy matches. The following search matches all documents that have a word within 1 edit distance of “foo”: `foo~1`

Results provided by Lunr.js

# ``twisted`.`web`.`template`.`Tag``

class documentation

`class Tag: (source)`

View In Hierarchy

A `Tag` represents an XML tags with a tag name, attributes, and children. A `Tag` can be constructed using the special `twisted.web.template.tags` object, or it may be constructed directly with a tag name. `Tag`s have a special method, `__call__`, which makes representing trees of XML natural using pure python syntax.

Method | `__call__` | Add children and change attributes on this tag.
Method | `__repr__` | Undocumented
Method | `clear` | Clear any existing children from this tag.
Method | `clone` | Return a clone of this tag. If deep is True, clone all of this tag's children. Otherwise, just shallow copy the children list without copying the children themselves.
Method | `fillSlots` | Remember the slots provided at this position in the DOM.
Instance Variable | `attributes` | The attributes of the element.
Instance Variable | `children` | The contents of this `Tag`.
Instance Variable | `columnNumber` | The column number at which this tag was encountered in the XML file from which it was parsed.
Instance Variable | `filename` | The name of the XML file from which this tag was parsed.
Instance Variable | `lineNumber` | The line number on which this tag was encountered in the XML file from which it was parsed.
Instance Variable | `render` | The name of the render method to use for this `Tag`.
Instance Variable | `slotData` | The data which can fill slots.
Instance Variable | `tagName` | The name of the represented element.
Method | `_clone` | Clone a `Flattenable` object; used by `Tag.clone`.

def __call__(self, *children: `Flattenable`, **kw: `Flattenable`) -> `Tag`: (source)

Add children and change attributes on this tag.

This is implemented using __call__ because it then allows the natural syntax:

      table(tr1, tr2, width="100%", height="50%", border="1")

Children may be other tag instances, strings, functions, or any other object which has a registered flatten.

Attributes may be 'transparent' tag instances (so that `a(href=transparent(data="foo", render=myhrefrenderer))` works), strings, functions, or any other object which has a registered flattener.

If the attribute is a python keyword, such as 'class', you can add an underscore to the name, like 'class_'.

There is one special keyword argument, 'render', which will be used as the name of the renderer and saved as the 'render' attribute of this instance, rather than the DOM 'render' attribute in the attributes dictionary.

def __repr__(self) -> `str`: (source)

Undocumented

def clear(self) -> `Tag`: (source)

Clear any existing children from this tag.

def clone(self, deep: `bool` = True) -> `Tag`: (source)

Return a clone of this tag. If deep is True, clone all of this tag's children. Otherwise, just shallow copy the children list without copying the children themselves.

def fillSlots(self, **slots: `Flattenable`) -> `Tag`: (source)

Remember the slots provided at this position in the DOM.

During the rendering of children of this node, slots with names in `slots` will be rendered as their corresponding values.

Returns
`Tag` | `self`. This enables the idiom `return tag.fillSlots(...)` in renderers.

attributes: `Dict[Union[bytes, str], Flattenable]` = (source)

The attributes of the element.

children: `List[Flattenable]` = (source)

The contents of this `Tag`.

columnNumber: `Optional[int]` = (source)

The column number at which this tag was encountered in the XML file from which it was parsed.

If it was not parsed from an XML file, `None`.

filename: `Optional[str]` = (source)

The name of the XML file from which this tag was parsed.

If it was not parsed from an XML file, `None`.

lineNumber: `Optional[int]` = (source)

The line number on which this tag was encountered in the XML file from which it was parsed.

If it was not parsed from an XML file, `None`.

render: `Optional[str]` = (source)

The name of the render method to use for this `Tag`.

This name will be looked up at render time by the `twisted.web.template.Element` doing the rendering, via `twisted.web.template.Element.lookupRenderMethod`, to determine which method to call.

slotData: `Optional[Dict[str, Flattenable]]` = (source)

The data which can fill slots.

If present, a dictionary mapping slot names to renderable values. The values in this dict might be anything that can be present as the child of a `Tag`: strings, lists, `Tag`s, generators, etc.

tagName: `Union[bytes, str]` = (source)

The name of the represented element.

For a tag like `<div></div>`, this would be `"div"`.

def _clone(self, obj: `Flattenable`, deep: `bool`) -> `Flattenable`: (source)

Clone a `Flattenable` object; used by `Tag.clone`.

Note that both lists and tuples are cloned into lists.

Parameters
obj:`Flattenable` | an object with a clone method, a list or tuple, or something which should be immutable.
deep:`bool` | whether to continue cloning child objects; i.e. the contents of lists, the sub-tags within a tag.
Returns
`Flattenable` | a clone of `obj`.