Mercurial > genshi > mirror
annotate examples/basic/run.py @ 24:5a4d45703319 trunk
Cosmetic (mostly whitespace) changes.
author | cmlenz |
---|---|
date | Mon, 26 Jun 2006 17:54:00 +0000 |
parents | b4d17897d053 |
children | 1da51d718391 |
rev | line source |
---|---|
3 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 from datetime import datetime, timedelta | |
5 import os | |
6 import sys | |
7 | |
8 from markup.template import Context, TemplateLoader | |
9 | |
10 def test(): | |
11 base_path = os.path.dirname(os.path.abspath(__file__)) | |
21
b4d17897d053
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
17
diff
changeset
|
12 loader = TemplateLoader([base_path], auto_reload=True) |
3 | 13 |
14 start = datetime.now() | |
15 tmpl = loader.load('test.html') | |
16 print ' --> parse stage: ', datetime.now() - start | |
17 | |
17
74cc70129d04
Refactoring to address #6: all match templates are now processed by a single filter, which means that match templates added by included templates are properly applied. A side effect of this refactoring is that `Context` objects may not be reused across multiple template processing runs.
cmlenz
parents:
3
diff
changeset
|
18 data = dict(hello='<world>', skin='default', hey='ZYX', bozz=None, |
74cc70129d04
Refactoring to address #6: all match templates are now processed by a single filter, which means that match templates added by included templates are properly applied. A side effect of this refactoring is that `Context` objects may not be reused across multiple template processing runs.
cmlenz
parents:
3
diff
changeset
|
19 items=['Number %d' % num for num in range(1, 15)], |
74cc70129d04
Refactoring to address #6: all match templates are now processed by a single filter, which means that match templates added by included templates are properly applied. A side effect of this refactoring is that `Context` objects may not be reused across multiple template processing runs.
cmlenz
parents:
3
diff
changeset
|
20 prefix='#') |
3 | 21 |
17
74cc70129d04
Refactoring to address #6: all match templates are now processed by a single filter, which means that match templates added by included templates are properly applied. A side effect of this refactoring is that `Context` objects may not be reused across multiple template processing runs.
cmlenz
parents:
3
diff
changeset
|
22 print tmpl.generate(Context(**data)).render(method='html') |
3 | 23 |
24 times = [] | |
25 for i in range(100): | |
26 start = datetime.now() | |
17
74cc70129d04
Refactoring to address #6: all match templates are now processed by a single filter, which means that match templates added by included templates are properly applied. A side effect of this refactoring is that `Context` objects may not be reused across multiple template processing runs.
cmlenz
parents:
3
diff
changeset
|
27 list(tmpl.generate(Context(**data))) |
3 | 28 sys.stdout.write('.') |
29 sys.stdout.flush() | |
30 times.append(datetime.now() - start) | |
31 print | |
32 | |
33 total_ms = sum([t.seconds * 1000 + t.microseconds for t in times]) | |
34 print ' --> render stage: %s (avg), %s (min), %s (max)' % ( | |
35 timedelta(microseconds=total_ms / len(times)), | |
36 timedelta(microseconds=min([t.seconds * 1000 + t.microseconds for t in times])), | |
37 timedelta(microseconds=max([t.seconds * 1000 + t.microseconds for t in times]))) | |
38 | |
39 if __name__ == '__main__': | |
40 if '-p' in sys.argv: | |
41 import hotshot, hotshot.stats | |
42 prof = hotshot.Profile("template.prof") | |
43 benchtime = prof.runcall(test) | |
44 stats = hotshot.stats.load("template.prof") | |
45 stats.strip_dirs() | |
46 stats.sort_stats('time', 'calls') | |
47 stats.print_stats() | |
48 else: | |
49 test() |