Mercurial > genshi > genshi-test
annotate examples/includes/run.py @ 172:4b4e80b2b0b5
Fix for #30 (trouble using `py:def`inside a match template)
author | cmlenz |
---|---|
date | Fri, 18 Aug 2006 23:23:45 +0000 |
parents | 00835401c8cc |
children | 24757b771651 |
rev | line source |
---|---|
21
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
1 #!/usr/bin/python |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
3 |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
4 import os |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
5 import sys |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
6 import timing |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
7 |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
8 from markup.template import Context, TemplateLoader |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
9 |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
10 def test(): |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
11 base_path = os.path.dirname(os.path.abspath(__file__)) |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
12 loader = TemplateLoader([os.path.join(base_path, 'skins'), |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
13 os.path.join(base_path, 'module'), |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
14 os.path.join(base_path, 'common')]) |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
15 |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
16 timing.start() |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
17 tmpl = loader.load('test.html') |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
18 timing.finish() |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
19 print ' --> parse stage: %dms' % timing.milli() |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
20 |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
21 data = dict(hello='<world>', skin='default', hey='ZYX', bozz=None, |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
22 items=['Number %d' % num for num in range(1, 15)]) |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
23 |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
24 print tmpl.generate(Context(**data)).render(method='html') |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
25 |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
26 times = [] |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
27 for i in range(100): |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
28 timing.start() |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
29 list(tmpl.generate(Context(**data))) |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
30 timing.finish() |
22
31b13ddf9f53
Fix for the template engine plugin: the search path is now ignored if the requested template path is absolute.
cmlenz
parents:
21
diff
changeset
|
31 times.append(timing.milli()) |
21
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
32 sys.stdout.write('.') |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
33 sys.stdout.flush() |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
34 print |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
35 |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
36 print ' --> render stage: %dms (avg), %dms (min), %dms (max)' % ( |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
37 sum(times) / len(times), min(times), max(times)) |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
38 |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
39 if __name__ == '__main__': |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
40 if '-p' in sys.argv: |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
41 import hotshot, hotshot.stats |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
42 prof = hotshot.Profile("template.prof") |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
43 benchtime = prof.runcall(test) |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
44 stats = hotshot.stats.load("template.prof") |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
45 stats.strip_dirs() |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
46 stats.sort_stats('time', 'calls') |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
47 stats.print_stats() |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
48 else: |
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
diff
changeset
|
49 test() |