Class n.s.Tag(object):

Part of nevow.stan View Source View In Hierarchy

Known subclasses: nevow.stan.Comment

Implements interfaces: nevow.inevow.IQ

Tag instances represent XML tags with a tag name, attributes, and children. Tag instances can be constructed using the Prototype tags in the 'tags' module, or may be constructed directly with a tag name. Tags have two special methods, __call__ and __getitem__, which make representing trees of XML natural using pure python syntax. See the docstrings for these methods for more details.
Line # Kind Name Docs
181 Method __init__ Undocumented
197 Method fillSlots Remember the stan 'slotValue' with the name 'slotName' at this position
207 Method patternGenerator Returns a psudeo-Tag which will generate clones of matching
226 Method allPatterns Return a list of all matching pattern tags, cloned.
237 Method onePattern Return a single matching pattern, cloned.
258 Method __call__ Change attributes of this tag. This is implemented using
316 Method __getitem__ Add children to this tag. Multiple children may be added by
341 Method __iter__ Prevent an infinite loop if someone tries to do
353 Method precompilable Is this tag precompilable?
377 Method clone Return a clone of this tag. If deep is True, clone all of this
408 Method clear Clear any existing children from this tag.
415 Method __repr__ Undocumented
425 Method freeze Freeze this tag so that making future calls to __call__ or __getitem__ on the
def __init__(self, tag, attributes=None, children=None, specials=None): (source)
Undocumented
def fillSlots(self, slotName, slotValue): (source)
Remember the stan 'slotValue' with the name 'slotName' at this position in the DOM. During the rendering of children of this node, slots with the name 'slotName' will render themselves as 'slotValue'.
def patternGenerator(self, pattern, default=None): (source)

Returns a psudeo-Tag which will generate clones of matching pattern tags forever, looping around to the beginning when running out of unique matches.

If no matches are found, and default is None, raise an exception, otherwise, generate clones of default forever.

You can use the normal stan syntax on the return value.

Useful to find repeating pattern elements. Example rendering function:
>>> def simpleSequence(context, data):
...   pattern = context.patternCloner('item')
...   return [pattern(data=element) for element in data]
def allPatterns(self, pattern): (source)

Return a list of all matching pattern tags, cloned.

Useful if you just want to insert them in the output in one place.

E.g. the sequence renderer's header and footer are found with this.
def onePattern(self, pattern): (source)

Return a single matching pattern, cloned.

If there is more than one matching pattern or no matching patterns, raise an exception.

Useful in the case where you want to locate one and only one sub-tag and do something with it.
def __call__(self, **kw): (source)
overridden in nevow.stan.Comment
Change attributes of this tag. This is implemented using __call__ because it then allows the natural syntax:
 table(width="100%", height="50%", border="1")

Attributes may be 'invisible' tag instances (so that a(href=invisible(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_'.

A few magic attributes have values other than these, as they are not serialized for output but rather have special purposes of their own:
  • data: The value is saved on the context stack and passed to render functions.
  • render: A function to call that may modify the tag in any way desired.
  • remember: Remember the value on the context stack with context.remember(value) for later lookup with context.locate()
  • pattern: Value should be a key that can later be used to locate this tag with context.patternGenerator() or context.allPatterns()
  • key: A string used to give the node a unique label. This is automatically namespaced, so in span(key="foo")[span(key="bar")] the inner span actually has a key of 'foo.bar'. The key is intended for use as e.g. an html 'id' attribute, but will is not automatically output.
  • macro - A function which will be called once in the lifetime of the template, when the template is loaded. The return result from this function will replace this Tag in the template.
def __getitem__(self, children): (source)

Add children to this tag. Multiple children may be added by passing a tuple or a list. Children may be other tag instances, strings, functions, or any other object which has a registered flatten.

This is implemented using __getitem__ because it then allows the natural syntax:
 html[
     head[
         title["Hello World!"]
     ],
     body[
         "This is a page",
         h3["How are you!"],
         div(style="color: blue")["I hope you are fine."]
     ]
 ]
def __iter__(self): (source)
Prevent an infinite loop if someone tries to do for x in stantaginstance:
def precompilable(self): (source)

Is this tag precompilable?

Tags are precompilable if they will not be modified by a user render function.

Currently, the following attributes prevent the tag from being precompiled:
  • render (because the function can modify its own tag)
  • pattern (because it is locatable and thus modifiable by an enclosing renderer)
def clone(self, deep=True, clearPattern=False): (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 clear(self): (source)
Clear any existing children from this tag.
def __repr__(self): (source)
Undocumented
def freeze(self): (source)
Freeze this tag so that making future calls to __call__ or __getitem__ on the return value will result in clones of this tag.
API Documentation for Nevow, generated by pydoctor.