exception.py
This file
Path
tests/runtime/exception.py
113 lines · 3.1 KiB · Python
Last changed by
converted unit tests, started rewriting filtersChristoph Hackbefore adoptione9e43bb
History of this fileTake it
The walk stopped after 200 commits: lines older than 5a8e497 point at it.
[svn] merged newparser into trunkArmin Ronacherbefore adoption1cc232c
line 1why, one step back1import os[svn] moved some of the documentation into docstringsArmin Ronacherbefore adoption5a8e497
line 2why, one step back2import sys[svn] merged newparser into trunkArmin Ronacherbefore adoption1cc232c
lines 3–5why, one step back3sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))45import jdebugconverted unit tests, started rewriting filtersChristoph Hackbefore adoptione9e43bb
lines 6–7why, one step back6from jinja2 import Environment, DictLoader7from jinja2.exceptions import TemplateNotFound[svn] moved some of the documentation into docstringsArmin Ronacherbefore adoption5a8e497
lines 8–37why, one step back8from wsgiref.simple_server import make_server910e = Environment(loader=DictLoader({11 '/': u'''12<html>13 <head>14 <title>Various Broken Templates</title>15 <style type="text/css">16 body {17 margin: 2em;18 font-size: 1.5em;19 font-family: sans-serif20 }21 a {22 color: #d00;23 }24 </style>25 </head>26 <body>27 <h1>Various Broken Templates</h1>28 <p>29 This small WSGI application serves some Jinja templates that30 are just broken. It uses the colubrid traceback middleware to31 render those errors including source code.32 </p>33 <ul>34 <li><a href="syntax_error">syntax error</a></li>35 <li><a href="runtime_error">runtime error</a></li>36 <li><a href="nested_syntax_error">nested syntax error</a></li>37 <li><a href="nested_runtime_error">nested runtime error</a></li>[svn] added "debugger of awesomeness" :DArmin Ronacherbefore adoptiona7804ef
line 38why, one step back38 <li><a href="code_runtime_error">runtime error in code</a></li>[svn] moved some of the documentation into docstringsArmin Ronacherbefore adoption5a8e497
lines 39–40why, one step back39 <li><a href="syntax_from_string">a syntax error from string</a></li>40 <li><a href="runtime_from_string">runtime error from a string</a></li>[svn] merged newparser into trunkArmin Ronacherbefore adoption1cc232c
line 41why, one step back41 <li><a href="multiple_templates">multiple templates</a></li>[svn] moved some of the documentation into docstringsArmin Ronacherbefore adoption5a8e497
lines 42–59why, one step back42 </ul>43 </body>44</html>45''',46 '/syntax_error': u'''47{% for item in foo %}48 ...49{% endif %}50 ''',51 '/runtime_error': u'''52{% set foo = 1 / 0 %}53 ''',54 '/nested_runtime_error': u'''55{% include 'runtime_broken' %}56 ''',57 '/nested_syntax_error': u'''58{% include 'syntax_broken' %}59 ''',[svn] added groupby filter and fixed some small bugsArmin Ronacherbefore adoptione39a5d2
lines 60–61why, one step back60 '/code_runtime_error': u'''We have a runtime error here:61 {{ broken() }}''',[svn] merged newparser into trunkArmin Ronacherbefore adoption1cc232c
lines 62–64why, one step back62 '/multiple_templates': '''\63{{ fire_multiple_broken() }}64''',[svn] added "debugger of awesomeness" :DArmin Ronacherbefore adoptiona7804ef
line 65why, one step back65[svn] moved some of the documentation into docstringsArmin Ronacherbefore adoption5a8e497
lines 66–70why, one step back66 'runtime_broken': '''\67This is an included template68{% set a = 1 / 0 %}''',69 'syntax_broken': '''\70This is an included template[svn] merged newparser into trunkArmin Ronacherbefore adoption1cc232c
lines 71–81why, one step back71{% raw %}just some foo''',72 'multiple_broken': '''\73Just some context:74{% include 'macro_broken' %}75{{ broken() }}76''',77 'macro_broken': '''\78{% macro broken %}79 {{ 1 / 0 }}80{% endmacro %}81'''[svn] moved some of the documentation into docstringsArmin Ronacherbefore adoption5a8e497
line 82why, one step back82}))[svn] merged newparser into trunkArmin Ronacherbefore adoption1cc232c
lines 83–84why, one step back83e.globals['fire_multiple_broken'] = lambda: \84 e.get_template('multiple_broken').render()[svn] moved some of the documentation into docstringsArmin Ronacherbefore adoption5a8e497
lines 85–89why, one step back8586FAILING_STRING_TEMPLATE = '{{ 1 / 0 }}'87BROKEN_STRING_TEMPLATE = '{% if foo %}...{% endfor %}'8889[svn] added "debugger of awesomeness" :DArmin Ronacherbefore adoptiona7804ef
lines 90–93why, one step back90def broken():91 raise RuntimeError("I'm broken")9293[svn] moved some of the documentation into docstringsArmin Ronacherbefore adoption5a8e497
lines 94–106why, one step back94def test(environ, start_response):95 path = environ.get('PATH_INFO' or '/')96 try:97 tmpl = e.get_template(path)98 except TemplateNotFound:99 if path == '/syntax_from_string':100 tmpl = e.from_string(BROKEN_STRING_TEMPLATE)101 elif path == '/runtime_from_string':102 tmpl = e.from_string(FAILING_STRING_TEMPLATE)103 else:104 start_response('404 NOT FOUND', [('Content-Type', 'text/plain')])105 return ['NOT FOUND']106 start_response('200 OK', [('Content-Type', 'text/html; charset=utf-8')])[svn] added "debugger of awesomeness" :DArmin Ronacherbefore adoptiona7804ef
line 107why, one step back107 return [tmpl.render(broken=broken).encode('utf-8')][svn] moved some of the documentation into docstringsArmin Ronacherbefore adoption5a8e497
line 108why, one step back108[svn] added "debugger of awesomeness" :DArmin Ronacherbefore adoptiona7804ef
line 109why, one step back109[svn] moved some of the documentation into docstringsArmin Ronacherbefore adoption5a8e497
line 110why, one step back110if __name__ == '__main__':[svn] added "debugger of awesomeness" :DArmin Ronacherbefore adoptiona7804ef
line 111why, one step back111 from werkzeug.debug import DebuggedApplication[svn] merged newparser into trunkArmin Ronacherbefore adoption1cc232c
line 112why, one step back112 app = DebuggedApplication(test, True)[svn] moved some of the documentation into docstringsArmin Ronacherbefore adoption5a8e497
line 113why, one step back113 make_server("localhost", 7000, app).serve_forever()