Module tales
source code
TODO docstring
Special TALES attributes
Although TALES will search the attributes and item of an object when
traversing it, it may be useful in some situations to provide TALES
with specific attributes and methods.
Naming convention
When traversing object o with path element "a", TALES
with first look for an attribute or method named
"_tales_a". This allows classes to provide additional
attributes, or even to override existing attributes in TALES.
Method decorators
This module provides a set of decorators (all functions named
``tales_X``) to be used with methods (either standard or TALES
specific -- see `Naming convention`_) to customize the way TALES uses
those methods.
Wrapping
In some cases, the naming convention and method decorators are not
sufficient (i.e. when a mixin class should use the TALES specific
version of an underlying method). For those cases, classes may
provide the ``__wrap_with_tales_context__`` method. TALES will look
for this method just before attempting to traverse an object, and if
found, will replace that object by the result of the method.
Note that the wrapping will happen just before traversing: TALES
will never return a wrapped object as the result of an
expression.
TALES Global Methods
TALES global methods are functions that are available anywhere in a
TALES path.
Warning
TALES global method should be avoided as much as possible, since
they clutter the attribute space in interactive TALES editing, and
may induce unexpected behaviours. However, there are some uses to
them.
|
|
|
|
|
|
|
|
|
|
|
get_global_method(name)
Retrieves a global method, or return None if no such global method
has been registered. |
source code
|
|
|
iter_global_methods()
Iter over all the global method names. |
source code
|
|
|
|
|
|
|
|
Decorator for TALES full-path-functions.
A full-path-function will be immediately invoked, with the rest of the
path as its sole argument.
|
Decorator for TALES path1-functions.
A path1-function will be called with the next path element as its
argument, rather than searching for an attribute or key with that
name.
See advene.model.core.meta for an example.
|
Decorator for TALES context-functions.
When the last item of a path, and no-call is not used, a
context-function is invoked with the context as its argument (rather than
without any argument for other functions).
:see-also: `tales_use_context`
|
Decorator for TALES property.
A TALES property is similar in use to python's properties: it will
automatically be called (with the context as its sole parameter) *even*
if it has a subpath or if ``no-call:`` is used.
:see-also: `tales_use_context`
|
Decorator with 1 argument to be used with TALES properties and
context-functions (or it will have no effect).
If the function expects a specific context variable rather than the
context itself, the name of the variable can be specified with this
decorator.
Example:
@tales_property
@tales_use_as_context("package")
def some_method(self, a_package):
...
|
Register f as a global method, under the given name, or under its own
name if no name is provided.
f must accept two arguments: the object retrieved from the previous
TALES path, and the TALES context.
|
Unregister a global method. The parameter is the name of the global
method, or can be the function if it has been registered under its own
name.
|