/
__init__.py
56 lines (37 loc) · 1.21 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import sys
from jinja2 import Environment, FileSystemLoader
# Set the template environment.
env = Environment(loader=FileSystemLoader(os.path.abspath(os.path.join(
os.path.dirname(__file__), 'templates'))))
# Application wrapped by the debugger.
_debugged_app = None
# werkzeug.debug.utils
def get_template(filename):
return env.get_template(filename)
def render_template(template_filename, **context):
return get_template(template_filename).render(**context)
def get_debugged_app(app):
global _debugged_app
# Wrap app with the debugger.
if _debugged_app is None:
from werkzeug import DebuggedApplication
_debugged_app = DebuggedApplication(app, evalex=True)
return _debugged_app
# Monkeypatches
# -------------
# werkzeug.debug.console.HTMLStringO
def seek(self, n, mode=0):
pass
def readline(self):
if len(self._buffer) == 0:
return ''
ret = self._buffer[0]
del self._buffer[0]
return ret
# Patch utils first, to avoid loading Werkzeug's template.
sys.modules['werkzeug.debug.utils'] = sys.modules[__name__]
# Apply all other patches.
from werkzeug.debug.console import HTMLStringO
HTMLStringO.seek = seek
HTMLStringO.readline = readline