Skip to content
Myr

exception.py

This file

Path

tests/runtime/exception.py

86 lines · 2.4 KiB · Python

Last changed by

[svn] improved debugging support. it's not possible to catch errors of templates without loaders tooArmin Ronacherbefore adoption10dae5b

History of this file

Take it

[svn] fixed supering in jinja, documented it, added lipsum()Armin Ronacherbefore adoption34f3042

lines 1–2why, one step back
1import jdebug
2import sys

[svn] implemented compile time error handlingArmin Ronacherbefore adoption8ff24c4

lines 3–4why, one step back
3from jinja import Environment, DictLoader
4from jinja.exceptions import TemplateNotFound

[svn] moved all jinja tests into a runtime folder so that we have enough space for the new unittestsArmin Ronacherbefore adoptionaa5adfa

lines 5–6why, one step back
5from wsgiref.simple_server import make_server
6

[svn] implemented compile time error handlingArmin Ronacherbefore adoption8ff24c4

lines 7–34why, one step back
7e = 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-serif17 }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 that27 are just broken. It uses the colubrid traceback middleware to28 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>

[svn] improved debugging support. it's not possible to catch errors of templates without loaders tooArmin Ronacherbefore adoption10dae5b

lines 35–36why, one step back
35 <li><a href="syntax_from_string">a syntax error from string</a></li>
36 <li><a href="runtime_from_string">runtime error from a string</a></li>

[svn] implemented compile time error handlingArmin Ronacherbefore adoption8ff24c4

lines 37–63why, one step back
37 </ul>
38 </body>39</html>40''',41 '/syntax_error': u'''42{% for item in foo %}43 ...44{% endif %}45 ''',46 '/runtime_error': u'''47{% set foo = 1 / 0 %}48 ''',49 '/nested_runtime_error': u'''50{% include 'runtime_broken' %}51 ''',52 '/nested_syntax_error': u'''53{% include 'syntax_broken' %}54 ''',5556 'runtime_broken': '''\57This is an included template58{% set a = 1 / 0 %}''',59 'syntax_broken': '''\60This is an included template61{% raw %}just some foo'''62}))63

[svn] improved debugging support. it's not possible to catch errors of templates without loaders tooArmin Ronacherbefore adoption10dae5b

lines 64–65why, one step back
64FAILING_STRING_TEMPLATE = '{{ 1 / 0 }}'
65BROKEN_STRING_TEMPLATE = '{% if foo %}...{% endfor %}'

[svn] implemented compile time error handlingArmin Ronacherbefore adoption8ff24c4

line 66why, one step back
66

[svn] improved debugging support. it's not possible to catch errors of templates without loaders tooArmin Ronacherbefore adoption10dae5b

line 67why, one step back
67

[svn] implemented compile time error handlingArmin Ronacherbefore adoption8ff24c4

line 68why, one step back
68def test(environ, start_response):

[svn] improved debugging support. it's not possible to catch errors of templates without loaders tooArmin Ronacherbefore adoption10dae5b

line 69why, one step back
69 path = environ.get('PATH_INFO' or '/')

[svn] implemented compile time error handlingArmin Ronacherbefore adoption8ff24c4

line 70why, one step back
70 try:

[svn] improved debugging support. it's not possible to catch errors of templates without loaders tooArmin Ronacherbefore adoption10dae5b

line 71why, one step back
71 tmpl = e.get_template(path)

[svn] implemented compile time error handlingArmin Ronacherbefore adoption8ff24c4

line 72why, one step back
72 except TemplateNotFound:

[svn] improved debugging support. it's not possible to catch errors of templates without loaders tooArmin Ronacherbefore adoption10dae5b

lines 73–79why, one step back
73 if path == '/syntax_from_string':
74 tmpl = e.from_string(BROKEN_STRING_TEMPLATE)75 elif path == '/runtime_from_string':76 tmpl = e.from_string(FAILING_STRING_TEMPLATE)77 else:78 start_response('404 NOT FOUND', [('Content-Type', 'text/plain')])79 return ['NOT FOUND']

[svn] implemented compile time error handlingArmin Ronacherbefore adoption8ff24c4

lines 80–81why, one step back
80 start_response('200 OK', [('Content-Type', 'text/html; charset=utf-8')])
81 return [tmpl.render().encode('utf-8')]

[svn] moved all jinja tests into a runtime folder so that we have enough space for the new unittestsArmin Ronacherbefore adoptionaa5adfa

line 82why, one step back
82

[svn] fixed supering in jinja, documented it, added lipsum()Armin Ronacherbefore adoption34f3042

lines 83–86why, one step back
83if __name__ == '__main__':
84 from colubrid.debug import DebuggedApplication85 app = DebuggedApplication(test)86 make_server("localhost", 7000, app).serve_forever()