本文整理汇总了Python中_parse.Template类的典型用法代码示例。如果您正苦于以下问题:Python Template类的具体用法?Python Template怎么用?Python Template使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Template类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
def parse(template, context, _locals, timed, cache, repeat):
# use of extensions to inject _locals
_sandbox.extensions = _locals
try:
if timed and cache:
t = timeit.Timer('tpl.render()', 'from __main__ import Template\ntpl = Template("{0}")\ncontext={1}'.format(template, str(context)))
print '%.2f ms %s' % (1000 * t.timeit(100)/100, template)
elif timed:
t = timeit.Timer('Template("{0}").render()'.format(template), 'from __main__ import Template')
print '%.2f ms %s' % (1000 * t.timeit(repeat)/repeat, template)
else:
t = Template(template)
print '<!DOCTYPE html>\n'+etree.tostring(etree.fromstring(t.render(**context)), pretty_print=True)
except Exception as e:
print 'Exception rendering ', template
print e
示例2: test_py_nested_for
def test_py_nested_for(self):
parsed, expected = self.t['py_nested_for']
parsed = Template(parsed).render()
self.assertEqual(parsed.strip(), expected.strip())
示例3: test_py_mixed_content
def test_py_mixed_content(self):
parsed, expected = self.t['py_mixed_content']
parsed = Template(parsed).render()
self.assertEqual(parsed.strip(), expected.strip())
示例4: test_py_looping
def test_py_looping(self):
parsed, expected = self.t['py_looping']
parsed = Template(parsed).render()
self.assertEqual(parsed.strip(), expected.strip())
示例5: test_py_include
def test_py_include(self):
parsed, expected = self.t['py_include']
parsed = Template(parsed).render()
self.assertEqual(parsed.strip(), expected.strip())
示例6: test_py_complex3
def test_py_complex3(self):
parsed, expected = self.t['py_complex3']
parsed = Template(parsed).render()
self.assertEqual(parsed.strip(), expected.strip())
示例7: test_py_block_default
def test_py_block_default(self):
parsed, expected = self.t['py_block_default']
parsed = Template(parsed).render()
self.assertEqual(parsed.strip(), expected.strip())
示例8: test_basic_variable_indent
def test_basic_variable_indent(self):
parsed, expected = self.t['basic_variable_indent']
parsed = Template(parsed).render()
self.assertEqual(parsed.strip(), expected.strip())
示例9: test_basic_tag_hashes
def test_basic_tag_hashes(self):
parsed, expected = self.t['basic_tag_hashes']
parsed = Template(parsed).render()
self.assertEqual(parsed.strip(), expected.strip())
示例10: test_basic_multilinetext
def test_basic_multilinetext(self):
parsed, expected = self.t['basic_multilinetext']
parsed = Template(parsed).render()
self.assertEqual(parsed.strip(), expected.strip())
示例11: test_basic_ending_colon
def test_basic_ending_colon(self):
parsed, expected = self.t['basic_ending_colon']
parsed = Template(parsed).render()
self.assertEqual(parsed.strip(), expected.strip())
示例12: id
if r is None:
return ''
py_id = id(self.py_q)
py_parse = py_locals['__py_parse__']
doc_py(r, py_id, py_parse)
return r.tostring()
if __name__ == '__main__':
import sys
import codecs
from time import time
_f = sys.argv[1]
#print parse(_f)
t = Template(_f)
if '-p' in sys.argv:
def run():
for x in range(2000):
t.render()
import cProfile, pstats
prof = cProfile.Profile()
prof.run('run()')
stats = pstats.Stats(prof)
stats.strip_dirs()
stats.sort_stats('cumulative')
stats.print_stats(25)
else:
print t.render()