utils module.
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'
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'
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('&<>"\'')
"&<>"'"
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_type.
>>> str(format_value({}))
'{}'
lexer module
Inline preprocessor
Generic widget preprocessor.
HTML element input of type text. Value is rendered only if evaluated to boolean True.
Interpretate text as string expression or python expression.
HTML element input hidden.
Multiple HTML element input of type hidden.
HTML element input of type password. Value is rendered only if it is not None or ‘’.
parser module
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:"']
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'))")
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')]
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'
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"'})
jinja2 extension module.
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'
mako extension module.
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.template extension module.
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'
tenjin extension module.
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'