Modules

wheezy.html

wheezy.html.utils

utils module.

wheezy.html.utils.date_format_provider(value, format_spec=None)[source]

Default format provider for datetime.date.

Requires year >= 1900, otherwise returns an empty string.

>>> date_format_provider(date.min)
''
>>> date_format_provider(min_date)
'1900/01/01'
>>> date_format_provider(date(2012, 2, 6))
'2012/02/06'
wheezy.html.utils.datetime_format_provider(value, format_spec=None)[source]

Default format provider for datetime.datetime.

Requires year >= 1900, otherwise returns an empty string.

>>> datetime_format_provider(datetime.min)
''
>>> datetime_format_provider(min_datetime)
'1900/01/01 00:00'
>>> datetime_format_provider(datetime(2012, 2, 6, 15, 17))
'2012/02/06 15:17'
wheezy.html.utils.escape_html(s)[source]

Escapes a string so it is valid within HTML. Converts None to an empty string. Raises TypeError is s is not a string or unicode object.

>>> html_escape(None)
''
>>> escape_html('&<>"\'')
"&amp;&lt;&gt;&quot;'"
wheezy.html.utils.escape_html_native(s)

Escapes a string so it is valid within HTML. Converts None to an empty string. Raises TypeError is s is not a string or unicode object.

>>> html_escape(None)
''
>>> escape_html('&<>"\'')
"&amp;&lt;&gt;&quot;'"
wheezy.html.utils.format_value(value, format_spec=None, format_provider=None)[source]

Formats widget value.

format_provider - a callable of the following form:

def my_formatter(value, format_spec):
    return value_formatted
>>> str(format_value(date(2012, 2, 6), '%m-%d-%y'))
'02-06-12'
>>> format_value(date(2012, 2, 6),
...         format_provider=lambda value, ignore:
...         value.strftime('%m-%d-%y'))
'02-06-12'
>>> list(map(str, format_value([1, 2, 7])))
['1', '2', '7']
>>> format_value([])
()

If format provider is unknown apply str.

>>> str(format_value({}))
'{}'
wheezy.html.utils.html_escape(s)

Escapes a string so it is valid within HTML. Converts None to an empty string. Raises TypeError is s is not a string or unicode object.

>>> html_escape(None)
''
>>> escape_html('&<>"\'')
"&amp;&lt;&gt;&quot;'"

wheezy.html.ext.lexer

lexer module

class wheezy.html.ext.lexer.InlinePreprocessor(pattern, directories, strategy=None)[source]

Inline preprocessor

class wheezy.html.ext.lexer.Preprocessor(widgets_pattern)[source]

Generic widget preprocessor.

checkbox(expr, params, expr_filter)[source]

HTML element input of type checkbox.

dropdown(expr, params, expr_filter)[source]

HTML element select.

emptybox(expr, params, expr_filter)[source]

HTML element input of type text. Value is rendered only if evaluated to boolean True.

error(expr, params, expr_filter)[source]

General error message or field error.

error_class(name, class_)[source]

Checks for error and add css class error.

expression(text, expr_filter='')[source]

Interpretate text as string expression or python expression.

hidden(expr, params, expr_filter)[source]

HTML element input hidden.

info(expr, params, expr_filter)[source]

General info message.

input_helper(expr, params, expr_filter, input_type)[source]

HTML element input of type input_type.

join_attrs(kwargs)[source]

Joins kwargs as html attributes.

label(expr, params, expr_filter)[source]

HTML element label.

listbox(expr, params, expr_filter)[source]

HTML element select of type multiple.

message_helper(expr, params, expr_filter, msg_class)[source]

General info message.

multiple_checkbox(expr, params, expr_filter)[source]

Multiple HTML element input of type checkbox.

multiple_hidden(expr, params, expr_filter)[source]

Multiple HTML element input of type hidden.

password(expr, params, expr_filter)[source]

HTML element input of type password. Value is rendered only if it is not None or ‘’.

radio(expr, params, expr_filter)[source]

A group of HTML input elements of type radio.

textarea(expr, params, expr_filter)[source]

HTML element textarea.

textbox(expr, params, expr_filter)[source]

HTML element input of type text. Value is rendered only if it is not None or ‘’.

warning(expr, params, expr_filter)[source]

General warning message.

class wheezy.html.ext.lexer.WhitespacePreprocessor(rules, ignore_rules=None)[source]

Whitespace preprocessor.

wheezy.html.ext.parser

parser module

wheezy.html.ext.parser.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('"Account Type:"')
['"Account Type:"']
wheezy.html.ext.parser.parse_known_function(expr)[source]

Parses known functions.

>>> parse_known_function("dob")
('dob', 'dob')
>>> parse_known_function("dob.format()")
('dob', 'format_value(dob, None)')
>>> parse_known_function("user.dob.format(_('YYYY/MM/DD'))")
('user.dob', "format_value(user.dob, _('YYYY/MM/DD'))")
>>> parse_known_function("user.dob.format(format_provider=lambda value, ignore: value.strftime('%m-%d-%y'))")
('user.dob', "format_value(user.dob, format_provider=lambda value, ignore: value.strftime('%m-%d-%y'))")
wheezy.html.ext.parser.parse_kwargs(text)[source]

Parses key-value type of parameters.

>>> parse_kwargs('choices=account_types')
{'choices': 'account_types'}
>>> sorted(parse_kwargs('autocomplete="off", maxlength=12').items())
[('autocomplete', '"off"'), ('maxlength', '12')]
wheezy.html.ext.parser.parse_name(expr)[source]

Parses name from expression of the following form:

[object.]name[.format(...]
>>> parse_name('display_name')
'display_name'
>>> parse_name('account.display_name')
'display_name'
>>> parse_name('account.display_name.format(')
'display_name'
wheezy.html.ext.parser.parse_params(text)[source]

Parses function parameters.

>>> parse_params('')
([], {})
>>> parse_params('choices=account_types')
([], {'choices': 'account_types'})
>>> parse_params('"Account Type:"')
(['"Account Type:"'], {})
>>> parse_params('"Account Type:", class_="inline"')
(['"Account Type:"'], {'class': '"inline"'})
wheezy.html.ext.parser.parse_str_or_int(text)[source]

Interpretate text as string or int expression.

>>> parse_str_or_int('"Hello"')
'Hello'
>>> parse_str_or_int("'Hello'")
'Hello'
>>> parse_str_or_int('100')
'100'
>>> parse_str_or_int('model.username')

wheezy.html.ext.jinja2

jinja2 extension module.

class wheezy.html.ext.jinja2.InlineExtension(searchpath, fallback=False)[source]

Inline preprocessor. Rewrite {% inline “…” %} tag with file content. If fallback is True rewrite to {% include “…” %} tag.

>>> t = '1 {% inline "master.html" %} 2'
>>> m = RE_INLINE.search(t)
>>> m.group('path')
'master.html'
>>> t[:m.start()], t[m.end():]
('1 ', ' 2')
>>> m = RE_INLINE.search(' {% inline "shared/footer.html" %}')
>>> m.group('path')
'shared/footer.html'
preprocess(source, name, filename=None)[source]

This method is called before the actual lexing and can be used to preprocess the source. The filename is optional. The return value must be the preprocessed source.

class wheezy.html.ext.jinja2.Jinja2Preprocessor(variable_start_string=None, variable_end_string=None)[source]
class wheezy.html.ext.jinja2.WhitespaceExtension(environment)[source]
preprocess(source, name, filename=None)[source]

This method is called before the actual lexing and can be used to preprocess the source. The filename is optional. The return value must be the preprocessed source.

class wheezy.html.ext.jinja2.WidgetExtension(environment)[source]
preprocess(source, name, filename=None)[source]

This method is called before the actual lexing and can be used to preprocess the source. The filename is optional. The return value must be the preprocessed source.

wheezy.html.ext.mako

mako extension module.

class wheezy.html.ext.mako.MakoPreprocessor(skip_imports=False)[source]
wheezy.html.ext.mako.inline_preprocessor(directories, fallback=False)[source]

Inline preprocessor. Rewrite <%inline file=”…” /> tag with file content. If fallback is True rewrite to <%include file=”…” /> tag.

>>> t = '1 <%inline file="master.html"/> 2'
>>> m = RE_INLINE.search(t)
>>> m.group('path')
'master.html'
>>> t[:m.start()], t[m.end():]
('1 ', ' 2')
>>> m = RE_INLINE.search(' <%inline file="shared/footer.html"/>')
>>> m.group('path')
'shared/footer.html'

wheezy.html.ext.template

wheezy.template extension module.

class wheezy.html.ext.template.InlineExtension(searchpath, fallback=False)[source]

Inline preprocessor. Rewrite @inline(”…”) tag with file content. If fallback is True rewrite to @include(”…”) tag.

>>> t = '1 @inline("master.html") 2'
>>> m = RE_INLINE.search(t)
>>> m.group('path')
'master.html'
>>> t[:m.start()], t[m.end():]
('1 ', ' 2')
>>> m = RE_INLINE.search(' @inline("shared/footer.html")')
>>> m.group('path')
'shared/footer.html'
class wheezy.html.ext.template.WheezyPreprocessor[source]

wheezy.html.ext.tenjin

tenjin extension module.

class wheezy.html.ext.tenjin.TenjinPreprocessor[source]
wheezy.html.ext.tenjin.inline_preprocessor(directories, fallback=False)[source]

Inline preprocessor. Rewrite <?py inline(”…”) ?> tag with file content. If fallback is True rewrite to <?py include(”…”) ?> tag.

>>> t = '1 <?py inline("master.html") ?> 2'
>>> m = RE_INLINE.search(t)
>>> m.group('path')
'master.html'
>>> t[:m.start()], t[m.end():]
('1 ', ' 2')
>>> m = RE_INLINE.search(' <?py inline("shared/footer.html") ?>')
>>> m.group('path')
'shared/footer.html'