7.6 NamespaceMixin Class
Description: NamespaceMixin Class
Keywords: albatross

#
7.6 NamespaceMixin Class

Albatross only supplies one class for this function; the `NamespaceMixin` class. This mixin provides a local and global namespace for evaluating expressions embedded in HTML template files.

When the browser request is merged into the execution context the input field values are written to the local namespace.

`__init__`( | )

  When you inherit from the `NamespaceMixin` class you must call the constructor.

  The global namespace for evaluating Python expressions in HTML templates is initialised as an empty dictionary in the constructor.

`locals`
  An empty object which is used for the local namespace for evaluating expressions in HTML templates. It is initialised as an instance of an empty class in the constructor to allow values to simply be assigned to attributes of this member.

  Loading the session merges the session values into this member.

`clear_locals`( | )

  Resets the `locals` member to an empty object.

`set_globals`( | dict)

  Sets the global namespace for evaluating expressions to the dict argument.

  The `SimpleContext` class constructor automatically sets this to the globals of the function which invoked the `SimpleContext` constructor.

  The `run_template()` and `run_template_once()` methods of the `AppContext` calls this method to set global namespace to the globals of the calling function.

`eval_expr`( | expr)

  Called by the template file interpreter to evaluate the embedded Python expression in the expr argument.

`set_value`( | name, value)

  Sets the local namespace attribute named in the name argument to the value in the value argument. If the name argument begins with an underscore the method will raise a `SecurityError` exception.

  This is used by the application `merge_request()` method to merge individual browser request fields into the local namespace.

  There is a special ``backdoor'' identifier format which which directs browser request fields to the `set_backdoor()` method of `ListIterator` and `TreeIterator` objects. The backdoor identifiers are generated by the `<al-input>` and `<al-a>` tags to implement sequence and tree browsing requests.

  The method implements a parser which can handle names of the form:

    `name` | ::= | `identifier | list-backdoor | tree-backdoor`

    `identifier` | ::= | `identifier (("." identifier) | ("[" number "]"))*`

    `list-backdoor` | ::= | `operation "," iter`

    `tree-backdoor` | ::= | `operation "," iter "," alias`

    Download entire grammar as text.

`make_alias`( | name)

  Called to generate an alternate name for an object referenced in the `alias` attribute of an Albatross tag.

  The method resolves the name argument up to the last ``.'' and then calls the `albatross_alias()` method of the resolved object. The resolved object is then entered into the local namespace and the session using the name returned by `albatross_alias()`.

  The return value is a new name by combining the name returned by `albatross_alias()` with the part of the original name following and including the last ``.''.

  Refer to the `<al-input>` documentation on page in section 5.2.2 for an explanation of why this method exists.

`get_value`( | name)

  Retrieves the value identified by the name argument from the local namespace. If the named value does not exist then `None` is returned.

`has_value`( | name)

  Returns whether or not the value named in the name attribute exists in the local namespace.

`has_values`( | ...)

  Returns TRUE only if values named in the argument list exist in the local namespace.