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('&<>"\'') "&<>"'"
-
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('&<>"\'') "&<>"'"
-
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('&<>"\'') "&<>"'"
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.
-
emptybox(expr, params, expr_filter)[source]¶ HTML element input of type text. Value is rendered only if evaluated to boolean True.
-
expression(text, expr_filter='')[source]¶ Interpretate
textas string expression or python expression.
HTML element input hidden.
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 ‘’.
-
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.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
Truerewrite 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.jinja2.Jinja2Preprocessor(variable_start_string=None, variable_end_string=None)[source]¶
wheezy.html.ext.mako¶
mako extension module.
-
wheezy.html.ext.mako.inline_preprocessor(directories, fallback=False)[source]¶ Inline preprocessor. Rewrite <%inline file=”…” /> tag with file content. If fallback is
Truerewrite 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
Truerewrite 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'
wheezy.html.ext.tenjin¶
tenjin extension module.
-
wheezy.html.ext.tenjin.inline_preprocessor(directories, fallback=False)[source]¶ Inline preprocessor. Rewrite <?py inline(”…”) ?> tag with file content. If fallback is
Truerewrite 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'