예제 #1
0
파일: __main__.py 프로젝트: micheltem/dmsl
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
0
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
예제 #3
0
    _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):
예제 #4
0
    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):