Mercurial > genshi > genshi-test
view examples/basic/run.py @ 917:bcaa91c42b97 experimental-py3k
add support for python 3 to genshi.template expression evaluator:
* add support for python 3 AST:
* AST for raise has changed in Python 3.
* Python 3 adds AST nodes for individual arguments and Bytes.
* use genshi.compat functions for dealing with code objects.
* do not coerce byte strings to unicode in Python 3 ASTTransformer.
* replace doctests that reply on exception names with uglier but more compatible try:.. except:.. doctest
* handle filename preferences of Python 2 and 3 (2 prefers bytes, 3 prefers unicode).
* ifilter is gone from itertools in Python 3 so use repeat for tests instead.
author | hodgestar |
---|---|
date | Sun, 24 Oct 2010 22:39:08 +0000 |
parents | 24757b771651 |
children |
line wrap: on
line source
#!/usr/bin/python # -*- coding: utf-8 -*- import os import sys import time from genshi.template import TemplateLoader def test(): base_path = os.path.dirname(os.path.abspath(__file__)) loader = TemplateLoader([base_path], auto_reload=True) start = time.clock() tmpl = loader.load('test.html') print ' --> parse stage: %.4f ms' % ((time.clock() - start) * 1000) data = dict(hello='<world>', skin='default', hey='ZYX', bozz=None, items=['Number %d' % num for num in range(1, 15)], prefix='#') print tmpl.generate(**data).render(method='html') times = [] for i in range(1000): start = time.clock() list(tmpl.generate(**data)) times.append(time.clock() - start) sys.stdout.write('.') sys.stdout.flush() print print ' --> render stage: %s ms (average)' % ( (sum(times) / len(times) * 1000)) if __name__ == '__main__': if '-p' in sys.argv: import hotshot, hotshot.stats prof = hotshot.Profile("template.prof") benchtime = prof.runcall(test) stats = hotshot.stats.load("template.prof") stats.strip_dirs() stats.sort_stats('time', 'calls') stats.print_stats() else: test()