atenvironment package¶
Module contents¶
Top-level package for @environment.
-
exception
atenvironment.
EnvironMiss
[source]¶ Bases:
KeyError
Error indicating key is not present in environment.
-
exception
atenvironment.
UnknownKeyword
[source]¶ Bases:
BaseException
Exception indicating unknown keyword was provided to @environment decorator in **kwargs.
-
atenvironment.
environment
(*value, **kwargs)[source]¶ @environment decorator.
- Arguments:
value – one or more environment tokens requested
onerror – optional function to be called if any of the environment tokens in value is not present in environment. Such function must take one parameter what is a string value of a missing environment token. If onerror is not set, error is logged and EnvironMiss exception is raised
in_self – optional list of variable names in case instance property is to be initialized. If present, must be of same length as value. None in this list means particular element will be passed into the function and not into any instance property.
default – optional list of default values in case environment token in value is not present in environment. If present, must be of same length as value. onerror will not be called in such case.
The decorator checks for presence of environment tokens and if successful reads their values to the function parameters of the decorated function after any called parameters provided.
Eg. if calling function(a, b, c) that is decorated with @environment(‘X’) the function must be defined as def function(a, b, c, x) and X from the environment is read as last parameter.
When combining decorators or using multiple environment tokens in one @environment(‘X’, ‘Y’, ‘Z’) the values are loaded from the left to the right, from the top to the bottom.
If a function parameter for @environment is missing, when such function is called a TypeError is raised by the interpreter.