blob: c27a6df7a091b945aa7169e0b286a9a5825da123 [file] [log] [blame]
Armin Ronacher34f30422007-03-30 21:58:15 +02001import jdebug
2import sys
Armin Ronacher8ff24c42007-03-21 20:33:45 +01003from jinja import Environment, DictLoader
4from jinja.exceptions import TemplateNotFound
Armin Ronacher7977e5c2007-03-12 07:22:17 +01005from wsgiref.simple_server import make_server
Armin Ronacher7977e5c2007-03-12 07:22:17 +01006
Armin Ronacher8ff24c42007-03-21 20:33:45 +01007e = Environment(loader=DictLoader({
8 '/': u'''
9<html>
10 <head>
11 <title>Various Broken Templates</title>
12 <style type="text/css">
13 body {
14 margin: 2em;
15 font-size: 1.5em;
16 font-family: sans-serif
17 }
18 a {
19 color: #d00;
20 }
21 </style>
22 </head>
23 <body>
24 <h1>Various Broken Templates</h1>
25 <p>
26 This small WSGI application serves some Jinja templates that
27 are just broken. It uses the colubrid traceback middleware to
28 render those errors including source code.
29 </p>
30 <ul>
31 <li><a href="syntax_error">syntax error</a></li>
32 <li><a href="runtime_error">runtime error</a></li>
33 <li><a href="nested_syntax_error">nested syntax error</a></li>
34 <li><a href="nested_runtime_error">nested runtime error</a></li>
35 </ul>
36 </body>
37</html>
38''',
39 '/syntax_error': u'''
40{% for item in foo %}
41 ...
42{% endif %}
43 ''',
44 '/runtime_error': u'''
45{% set foo = 1 / 0 %}
46 ''',
47 '/nested_runtime_error': u'''
48{% include 'runtime_broken' %}
49 ''',
50 '/nested_syntax_error': u'''
51{% include 'syntax_broken' %}
52 ''',
53
54 'runtime_broken': '''\
55This is an included template
56{% set a = 1 / 0 %}''',
57 'syntax_broken': '''\
58This is an included template
59{% raw %}just some foo'''
60}))
61
62
63def test(environ, start_response):
64 try:
65 tmpl = e.get_template(environ.get('PATH_INFO') or '/')
66 except TemplateNotFound:
67 start_response('404 NOT FOUND', [('Content-Type', 'text/plain')])
68 return ['NOT FOUND']
69 start_response('200 OK', [('Content-Type', 'text/html; charset=utf-8')])
70 return [tmpl.render().encode('utf-8')]
Armin Ronacher7977e5c2007-03-12 07:22:17 +010071
Armin Ronacher34f30422007-03-30 21:58:15 +020072if __name__ == '__main__':
73 from colubrid.debug import DebuggedApplication
74 app = DebuggedApplication(test)
75 make_server("localhost", 7000, app).serve_forever()