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
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(t.render(**context)) #print '<!DOCTYPE html>\n'+etree.tostring(etree.fromstring(t.render(**context)), pretty_print=True) except Exception as e: print 'Exception rendering ', template print e
_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() ########NEW FILE######## __FILENAME__ = _pre from cutils import parse_attr, split_space, parse_inline, parse_ws, sub_str, sub_strs, var_assign from _sandbox import _open directives = ['%', '#', '.', '\\'] py_stmts = ['for', 'if', 'while', 'try', 'except', 'with', 'def'] def is_py_stmt(l): if l[-1] != u':': return False for stmt in py_stmts: if l.startswith(stmt):
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() ########NEW FILE######## __FILENAME__ = _pre from cutils import parse_attr, split_space, parse_inline, parse_ws, sub_str, sub_strs, var_assign from _sandbox import _open directives = ['%', '#', '.', '\\'] py_stmts = ['for', 'if', 'while', 'try', 'except', 'with', 'def'] def is_py_stmt(l): if l[-1] != u':': return False for stmt in py_stmts: if l.startswith(stmt):