Modules

wheezy.template

wheezy.template.builder

wheezy.template.engine

class wheezy.template.engine.Engine(loader, extensions, template_class=None)[source]

The core component of template engine.

get_template(name)[source]

Returns compiled template.

remove(name)[source]

Removes given name from internal cache.

render(name, ctx, local_defs, super_defs)[source]

Renders template by name in given context.

class wheezy.template.engine.Template(name, render_template)[source]

Simple template class.

wheezy.template.lexer

class wheezy.template.lexer.Lexer(lexer_rules, preprocessors=None, postprocessors=None, **ignore)[source]

Tokenizes input source per rules supplied.

tokenize(source)[source]

Translates source accoring to lexer rules into an iteratable of tokens.

wheezy.template.lexer.lexer_scan(extensions)[source]

Scans extensions for lexer_rules and preprocessors attributes.

wheezy.template.loader

class wheezy.template.loader.ChainLoader(loaders)[source]

Loads templates from loaders until first succeed.

list_names()[source]

Returns as list of names from all loaders.

load(name)[source]

Returns template by name from the first loader that succeed.

class wheezy.template.loader.DictLoader(templates)[source]

Loads templates from python dictionary.

templates - a dict where key corresponds to template name and value to template content.

list_names()[source]

List all keys from internal dict.

load(name)[source]

Returns template by name.

class wheezy.template.loader.FileLoader(directories, encoding='UTF-8')[source]

Loads templates from file system.

directories - search path of directories to scan for template. encoding - decode template content per encoding.

get_fullname(name)[source]

Returns a full path by a template name.

list_names()[source]

Return a list of names relative to directories. Ignores any files and directories that start with dot.

load(name)[source]

Loads a template by name from file system.

class wheezy.template.loader.PreprocessLoader(engine, ctx=None)[source]

Performs preprocessing of loaded template.

wheezy.template.loader.autoreload(engine, enabled=True)[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, parser_configs=None, **ignore)[source]

continue_tokens are used to insert end node right before them to simulate a block end. Such nodes have token value None.

out_tokens are combined together into a single node.

end_continue(tokens)[source]

If token is in continue_tokens prepend it with end token so it simulate a closed block.

wheezy.template.preprocessor

class wheezy.template.preprocessor.Preprocessor(runtime_engine_factory, engine, key_factory)[source]

Preprocess templates with engine and vary runtime templates by key_factory function using runtime_engine_factory.

wheezy.template.utils

wheezy.template.utils.find_all_balanced(text, start=0)[source]

Finds balanced ([ with ]) assuming that start is pointing to ( or [ in text.

wheezy.template.utils.find_balanced(text, start=0, start_sep='(', end_sep=')')[source]

Finds balanced start_sep with end_sep assuming that start is pointing to start_sep in text.

wheezy.template.ext.code

class wheezy.template.ext.code.CodeExtension(token_start='@')[source]

Includes support for embedded python code.

wheezy.template.ext.core

class wheezy.template.ext.core.CoreExtension(token_start='@', line_join='\')[source]

Includes basic statements, variables processing and markup.

wheezy.template.ext.core.rvalue_token(m)[source]

Produces variable token as r-value expression.

wheezy.template.ext.core.stmt_token(m)[source]

Produces statement token.

wheezy.template.ext.core.var_token(m)[source]

Produces variable token.

wheezy.template.ext.determined

class wheezy.template.ext.determined.DeterminedExtension(known_calls, runtime_token_start='@', token_start='#')[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)[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)[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)[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)[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"'})
wheezy.template.ext.determined.str_or_int(text)[source]

Ensures text as string or int expression.

>>> str_or_int('"default"')
True
>>> str_or_int("'Hello'")
True
>>> str_or_int('100')
True
>>> str_or_int('item.id')
False