class documentation

class Namespace(object):

Known subclasses: mako.runtime.ModuleNamespace, mako.runtime.TemplateNamespace

View In Hierarchy

Provides access to collections of rendering methods, which can be local, from other templates, or from imported modules.

To access a particular rendering method referenced by a .Namespace, use plain attribute access:

${some_namespace.foo(x, y, z)}

.Namespace also contains several built-in attributes described here.

Method get​_cached Return a value from the .Cache referenced by this .Namespace object's .Template.
Method get​_namespace Return a .Namespace corresponding to the given uri.
Method get​_template Return a .Template from the given uri.
Method include​_file Include a file at the given uri.
Class Variable filename The path of the filesystem file used for this .Namespace's module or template.
Class Variable module The Python module referenced by this .Namespace.
Class Variable template The .Template object referenced by this .Namespace, if any.
Class Variable uri The URI for this .Namespace's template.
Instance Variable context The .Context object for this .Namespace.
Method __getattr__ Undocumented
Method __init__ Undocumented
Method ​_get​_star Undocumented
Method ​_populate Undocumented
Class Variable ​_templateuri Undocumented
Instance Variable callables Undocumented
Instance Variable inherits Undocumented
Instance Variable name Undocumented
Property attr Access module level attributes by name.
Property cache Return the .Cache object referenced by this .Namespace object's .Template.
def get_cached(self, key, **kwargs):

Return a value from the .Cache referenced by this .Namespace object's .Template.

The advantage to this method versus direct access to the .Cache is that the configuration parameters declared in <%page> take effect here, thereby calling up the same configured backend as that configured by <%page>.

def get_namespace(self, uri):

Return a .Namespace corresponding to the given uri.

If the given uri is a relative URI (i.e. it does not contain a leading slash /), the uri is adjusted to be relative to the uri of the namespace itself. This method is therefore mostly useful off of the built-in local namespace, described in :ref:`namespace_local`.

In most cases, a template wouldn't need this function, and should instead use the <%namespace> tag to load namespaces. However, since all <%namespace> tags are evaluated before the body of a template ever runs, this method can be used to locate namespaces using expressions that were generated within the body code of the template, or to conditionally use a particular namespace.

def get_template(self, uri):

Return a .Template from the given uri.

The uri resolution is relative to the uri of this .Namespace object's .Template.

def include_file(self, uri, **kwargs):
Include a file at the given uri.
filename =

The path of the filesystem file used for this .Namespace's module or template.

If this is a pure module-based .Namespace, this evaluates to module.__file__. If a template-based namespace, it evaluates to the original template file location.

module =

The Python module referenced by this .Namespace.

If the namespace references a .Template, then this module is the equivalent of template.module, i.e. the generated module for the template.

template =
The .Template object referenced by this .Namespace, if any.
uri =

The URI for this .Namespace's template.

I.e. whatever was sent to .TemplateLookup.get_template().

This is the equivalent of .Template.uri.

context =

The .Context object for this .Namespace.

Namespaces are often created with copies of contexts that contain slightly different data, particularly in inheritance scenarios. Using the .Context off of a .Namespace one can traverse an entire chain of templates that inherit from one-another.

def __getattr__(self, key):
def __init__(self, name, context, callables=None, inherits=None, populate_self=True, calling_uri=None):
def _get_star(self):
def _populate(self, d, l):

Undocumented

_templateuri =

Undocumented

callables: tuple =
inherits =

Access module level attributes by name.

This accessor allows templates to supply "scalar" attributes which are particularly handy in inheritance relationships.

@property
cache =
Return the .Cache object referenced by this .Namespace object's .Template.