Package spade :: Module pyratemp :: Class TemplateEval
[hide private]
[frames] | no frames]

Class TemplateEval

source code


PseudoSandbox with some additional functions, which are useful
in the template.

Additional functions:
- "default" calls _default()
- "exists": calls _exists()

Instance Methods [hide private]
 
__init__(self) source code
 
_default(self, expr, default=None)
Return the eval-result of expr or a "fallback"-value.
source code
 
_exists(self, varname)
Test if a variable exists.
source code

Inherited from PseudoSandbox: compile, eval, register

Class Variables [hide private]

Inherited from PseudoSandbox: eval_allowed_globals

Method Details [hide private]

__init__(self)
(Constructor)

source code 
Overrides: PseudoSandbox.__init__

_default(self, expr, default=None)

source code 
Return the eval-result of expr or a "fallback"-value.

Use this in the template to use default-values for optional data.
The default-value is used if 'expr' does not exist/is invalid/results in None.

:Note: the variable-name has to be quoted! (like in eval)

:Example:
    ::
        @! default("optional_var","fallback_value") !@
        <!--(if default("optional",False))-->"YES"<!--(else)-->"NO"<!--(end)-->
        <!--(for i in default("optional_list",[]))-->

_exists(self, varname)

source code 

Test if a variable exists.

This tests if 'varname' exists in the current locals-namespace.

:Note: the variable-name has to be quoted! (like in eval)

This only works for single variable names. If you want to test complicated expressions, use i.e. _default. (i.e. _default("expr",False))