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