Modules¶
wheezy.template¶
-
class
wheezy.template.
Engine
(loader: wheezy.template.typing.Loader, extensions: List[Any], template_class: Optional[Callable[[str, Callable[[Mapping[str, Any], Mapping[str, Any], Mapping[str, Any]], str]], wheezy.template.typing.SupportsRender]] = None)[source]¶ The core component of template engine.
-
class
wheezy.template.
CodeExtension
(token_start: str = '@')[source]¶ Includes support for embedded python code.
-
class
wheezy.template.
CoreExtension
(token_start: str = '@', line_join: str = '\')[source]¶ Includes basic statements, variables processing and markup.
-
class
wheezy.template.
DictLoader
(templates: Mapping[str, str])[source]¶ Loads templates from python dictionary.
templates
- a dict where key corresponds to template name and value to template content.
-
class
wheezy.template.
FileLoader
(directories: List[str], encoding: str = 'UTF-8')[source]¶ Loads templates from file system.
directories
- search path of directories to scan for template.encoding
- decode template content per encoding.
-
class
wheezy.template.
PreprocessLoader
(engine: wheezy.template.engine.Engine, ctx: Optional[Mapping[str, Any]] = None)[source]¶ Performs preprocessing of loaded template.
-
class
wheezy.template.
Preprocessor
(runtime_engine_factory: Callable[[wheezy.template.typing.Loader], wheezy.template.engine.Engine], engine: wheezy.template.engine.Engine, key_factory: Callable[[Mapping[str, Any]], str])[source]¶ Preprocess templates with
engine
and vary runtime templates bykey_factory
function usingruntime_engine_factory
.
wheezy.template.builder¶
wheezy.template.compiler¶
wheezy.template.console¶
wheezy.template.engine¶
-
class
wheezy.template.engine.
Engine
(loader: wheezy.template.typing.Loader, extensions: List[Any], template_class: Optional[Callable[[str, Callable[[Mapping[str, Any], Mapping[str, Any], Mapping[str, Any]], str]], wheezy.template.typing.SupportsRender]] = None)[source]¶ The core component of template engine.
-
class
wheezy.template.engine.
Template
(name: str, render_template: Callable[[Mapping[str, Any], Mapping[str, Any], Mapping[str, Any]], str])[source]¶ Simple template class.
-
wheezy.template.engine.
complement_syntax_error
(err: SyntaxError, template_source: str, source: str) → SyntaxError[source]¶ Complements SyntaxError with template and source snippets, like one below:
File "shared/snippet/widget.html", line 4 if : template snippet: 02 <h1> 03 @msg!h 04 @if : 05 sd 06 @end generated snippet: 02 _b = []; w = _b.append; w('<h1>\n ') 03 w(h(msg)); w('\n') 04 if : 05 w(' sd\n') 06 if : ^ SyntaxError: invalid syntax
wheezy.template.lexer¶
-
class
wheezy.template.lexer.
Lexer
(lexer_rules: List[Tuple[Pattern[AnyStr], Callable[[Match[AnyStr]], Tuple[int, str, str]]]], preprocessors: Optional[List[Callable[[str], str]]] = None, postprocessors: Optional[List[Callable[[List[Tuple[int, str, str]]], str]]] = None, **ignore)[source]¶ Tokenizes input source per rules supplied.
wheezy.template.loader¶
-
class
wheezy.template.loader.
ChainLoader
(loaders: List[wheezy.template.typing.Loader])[source]¶ Loads templates from
loaders
until first succeed.
-
class
wheezy.template.loader.
DictLoader
(templates: Mapping[str, str])[source]¶ Loads templates from python dictionary.
templates
- a dict where key corresponds to template name and value to template content.
-
class
wheezy.template.loader.
FileLoader
(directories: List[str], encoding: str = 'UTF-8')[source]¶ Loads templates from file system.
directories
- search path of directories to scan for template.encoding
- decode template content per encoding.
-
class
wheezy.template.loader.
PreprocessLoader
(engine: wheezy.template.engine.Engine, ctx: Optional[Mapping[str, Any]] = None)[source]¶ Performs preprocessing of loaded template.
-
wheezy.template.loader.
autoreload
(engine: wheezy.template.engine.Engine, enabled: bool = True) → wheezy.template.engine.Engine[source]¶ Auto reload template if changes are detected in file.
Limitation: master (inherited), imported and preprocessed templates.
It is recommended to use application server that supports file reload instead.
wheezy.template.parser¶
-
class
wheezy.template.parser.
Parser
(parser_rules: Dict[str, Callable[[str], Union[str, List[str]]]], parser_configs: Optional[List[Callable[[wheezy.template.typing.ParserConfig], None]]] = None, **ignore)[source]¶ continue_tokens
are used to insertend
node right before them to simulate a block end. Such nodes have token valueNone
.out_tokens
are combined together into a single node.
wheezy.template.preprocessor¶
-
class
wheezy.template.preprocessor.
Preprocessor
(runtime_engine_factory: Callable[[wheezy.template.typing.Loader], wheezy.template.engine.Engine], engine: wheezy.template.engine.Engine, key_factory: Callable[[Mapping[str, Any]], str])[source]¶ Preprocess templates with
engine
and vary runtime templates bykey_factory
function usingruntime_engine_factory
.
wheezy.template.utils¶
wheezy.template.ext.code¶
wheezy.template.ext.core¶
-
class
wheezy.template.ext.core.
CoreExtension
(token_start: str = '@', line_join: str = '\')[source]¶ Includes basic statements, variables processing and markup.
-
wheezy.template.ext.core.
rvalue_token
(m: Match[str]) → Tuple[int, str, str][source]¶ Produces variable token as r-value expression.
wheezy.template.ext.determined¶
-
class
wheezy.template.ext.determined.
DeterminedExtension
(known_calls: List[str], runtime_token_start: str = '@', token_start: str = '#')[source]¶ Tranlates function calls between template engines.
Strictly determined known calls are converted to preprocessor calls, e.g.:
@_('Name:') @path_for('default') @path_for('static', path='/static/css/site.css')
Those that are not strictly determined are ignored and processed by runtime engine.
-
wheezy.template.ext.determined.
determined
(expression: str) → bool[source]¶ Checks if expresion is strictly determined.
>>> determined("'default'") True >>> determined('name') False >>> determined("'default', id=id") False >>> determined("'default', lang=100") True >>> determined('') True
-
wheezy.template.ext.determined.
parse_args
(text: str) → List[str][source]¶ Parses argument type of parameters.
>>> parse_args('') [] >>> parse_args('10, "x"') ['10', '"x"'] >>> parse_args("'x', 100") ["'x'", '100'] >>> parse_args('"default"') ['"default"']
-
wheezy.template.ext.determined.
parse_kwargs
(text: str) → Mapping[str, str][source]¶ Parses key-value type of parameters.
>>> parse_kwargs('id=item.id') {'id': 'item.id'} >>> sorted(parse_kwargs('lang="en", id=12').items()) [('id', '12'), ('lang', '"en"')]
-
wheezy.template.ext.determined.
parse_params
(text: str) → Tuple[List[str], Mapping[str, str]][source]¶ Parses function parameters.
>>> parse_params('') ([], {}) >>> parse_params('id=item.id') ([], {'id': 'item.id'}) >>> parse_params('"default"') (['"default"'], {}) >>> parse_params('"default", lang="en"') (['"default"'], {'lang': '"en"'})