Python mako.exceptions.html_error_template() Examples
The following are 30
code examples of mako.exceptions.html_error_template().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
mako.exceptions
, or try the search function
.
Example #1
Source File: runtime.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
def _render_error(template, context, error): if template.error_handler: result = template.error_handler(context, error) if not result: compat.reraise(*sys.exc_info()) else: error_template = exceptions.html_error_template() if context._outputting_as_unicode: context._buffer_stack[:] = [ util.FastEncodingBuffer(as_unicode=True) ] else: context._buffer_stack[:] = [ util.FastEncodingBuffer( error_template.output_encoding, error_template.encoding_errors, ) ] context._set_with_template(error_template) error_template.render_context(context, error=error)
Example #2
Source File: runtime.py From android_universal with MIT License | 6 votes |
def _render_error(template, context, error): if template.error_handler: result = template.error_handler(context, error) if not result: compat.reraise(*sys.exc_info()) else: error_template = exceptions.html_error_template() if context._outputting_as_unicode: context._buffer_stack[:] = [ util.FastEncodingBuffer(as_unicode=True)] else: context._buffer_stack[:] = [util.FastEncodingBuffer( error_template.output_encoding, error_template.encoding_errors)] context._set_with_template(error_template) error_template.render_context(context, error=error)
Example #3
Source File: runtime.py From ansible-cmdb with GNU General Public License v3.0 | 6 votes |
def _render_error(template, context, error): if template.error_handler: result = template.error_handler(context, error) if not result: compat.reraise(*sys.exc_info()) else: error_template = exceptions.html_error_template() if context._outputting_as_unicode: context._buffer_stack[:] = [ util.FastEncodingBuffer(as_unicode=True)] else: context._buffer_stack[:] = [util.FastEncodingBuffer( error_template.output_encoding, error_template.encoding_errors)] context._set_with_template(error_template) error_template.render_context(context, error=error)
Example #4
Source File: newsletters.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def serve_template(templatename, **kwargs): if plexpy.CONFIG.NEWSLETTER_CUSTOM_DIR: template_dir = plexpy.CONFIG.NEWSLETTER_CUSTOM_DIR else: interface_dir = os.path.join(str(plexpy.PROG_DIR), 'data/interfaces/') template_dir = os.path.join(str(interface_dir), plexpy.CONFIG.NEWSLETTER_TEMPLATES) if not plexpy.CONFIG.NEWSLETTER_INLINE_STYLES: templatename = templatename.replace('.html', '.internal.html') _hplookup = TemplateLookup(directories=[template_dir], default_filters=['unicode', 'h']) try: template = _hplookup.get_template(templatename) return template.render(**kwargs), False except: return exceptions.html_error_template().render(), True
Example #5
Source File: runtime.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def _render_error(template, context, error): if template.error_handler: result = template.error_handler(context, error) if not result: compat.reraise(*sys.exc_info()) else: error_template = exceptions.html_error_template() if context._outputting_as_unicode: context._buffer_stack[:] = [ util.FastEncodingBuffer(as_unicode=True) ] else: context._buffer_stack[:] = [ util.FastEncodingBuffer( error_template.output_encoding, error_template.encoding_errors, ) ] context._set_with_template(error_template) error_template.render_context(context, error=error)
Example #6
Source File: test_template.py From docassemble with MIT License | 6 votes |
def test_escapes_html_tags(self): from mako.exceptions import html_error_template x = Template(""" X: <% raise Exception('<span style="color:red">Foobar</span>') %> """) try: x.render() except: # <h3>Exception: <span style="color:red">Foobar</span></h3> markup = html_error_template().render(full=False, css=False) if compat.py3k: assert '<span style="color:red">Foobar</span></h3>'\ .encode('ascii') not in markup assert '<span style="color:red"'\ '>Foobar</span>'\ .encode('ascii') in markup else: assert '<span style="color:red">Foobar</span></h3>' \ not in markup assert '<span style="color:red"'\ '>Foobar</span>' in markup
Example #7
Source File: test_exceptions.py From docassemble with MIT License | 6 votes |
def test_custom_tback(self): try: raise RuntimeError("error 1") foo('bar') except: t, v, tback = sys.exc_info() try: raise RuntimeError("error 2") except: html_error = exceptions.html_error_template().\ render_unicode(error=v, traceback=tback) # obfuscate the text so that this text # isn't in the 'wrong' exception assert "".join(reversed(");93#&rab;93#&(oof")) in html_error
Example #8
Source File: runtime.py From SA-ctf_scoreboard with Creative Commons Zero v1.0 Universal | 6 votes |
def _render_error(template, context, error): if template.error_handler: result = template.error_handler(context, error) if not result: compat.reraise(*sys.exc_info()) else: error_template = exceptions.html_error_template() if context._outputting_as_unicode: context._buffer_stack[:] = [ util.FastEncodingBuffer(as_unicode=True)] else: context._buffer_stack[:] = [util.FastEncodingBuffer( error_template.output_encoding, error_template.encoding_errors)] context._set_with_template(error_template) error_template.render_context(context, error=error)
Example #9
Source File: test_exceptions.py From mako with MIT License | 6 votes |
def test_tback_no_trace_from_py_file(self): try: t = self._file_template("runtimeerr.html") t.render() except: t, v, tback = sys.exc_info() if not compat.py3k: # blow away tracebaack info sys.exc_clear() # and don't even send what we have. html_error = exceptions.html_error_template().render_unicode( error=v, traceback=None ) assert ( "local variable 'y' referenced before assignment" in html_error )
Example #10
Source File: test_exceptions.py From mako with MIT License | 6 votes |
def test_custom_tback(self): try: raise RuntimeError("error 1") foo("bar") # noqa except: t, v, tback = sys.exc_info() try: raise RuntimeError("error 2") except: html_error = exceptions.html_error_template().render_unicode( error=v, traceback=tback ) # obfuscate the text so that this text # isn't in the 'wrong' exception assert ( "".join(reversed(");touq&rab;touq&(oof")) in html_error or "".join(reversed(");43#&rab;43#&(oof")) in html_error )
Example #11
Source File: test_exceptions.py From mako with MIT License | 6 votes |
def test_py_utf8_html_error_template(self): try: foo = u("日本") # noqa raise RuntimeError("test") except: html_error = exceptions.html_error_template().render() if compat.py3k: assert "RuntimeError: test" in html_error.decode("utf-8") assert "foo = u("日本")" in html_error.decode( "utf-8" ) or "foo = u("日本")" in html_error.decode("utf-8") else: assert "RuntimeError: test" in html_error assert ( "foo = u("日本")" in html_error or "foo = u("日本")" in html_error )
Example #12
Source File: runtime.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
def _render_error(template, context, error): if template.error_handler: result = template.error_handler(context, error) if not result: compat.reraise(*sys.exc_info()) else: error_template = exceptions.html_error_template() if context._outputting_as_unicode: context._buffer_stack[:] = [ util.FastEncodingBuffer(as_unicode=True) ] else: context._buffer_stack[:] = [ util.FastEncodingBuffer( error_template.output_encoding, error_template.encoding_errors, ) ] context._set_with_template(error_template) error_template.render_context(context, error=error)
Example #13
Source File: runtime.py From jbox with MIT License | 6 votes |
def _render_error(template, context, error): if template.error_handler: result = template.error_handler(context, error) if not result: compat.reraise(*sys.exc_info()) else: error_template = exceptions.html_error_template() if context._outputting_as_unicode: context._buffer_stack[:] = [ util.FastEncodingBuffer(as_unicode=True)] else: context._buffer_stack[:] = [util.FastEncodingBuffer( error_template.output_encoding, error_template.encoding_errors)] context._set_with_template(error_template) error_template.render_context(context, error=error)
Example #14
Source File: runtime.py From teleport with Apache License 2.0 | 6 votes |
def _render_error(template, context, error): if template.error_handler: result = template.error_handler(context, error) if not result: compat.reraise(*sys.exc_info()) else: error_template = exceptions.html_error_template() if context._outputting_as_unicode: context._buffer_stack[:] = [ util.FastEncodingBuffer(as_unicode=True)] else: context._buffer_stack[:] = [util.FastEncodingBuffer( error_template.output_encoding, error_template.encoding_errors)] context._set_with_template(error_template) error_template.render_context(context, error=error)
Example #15
Source File: runtime.py From teleport with Apache License 2.0 | 6 votes |
def _render_error(template, context, error): if template.error_handler: result = template.error_handler(context, error) if not result: compat.reraise(*sys.exc_info()) else: error_template = exceptions.html_error_template() if context._outputting_as_unicode: context._buffer_stack[:] = [ util.FastEncodingBuffer(as_unicode=True) ] else: context._buffer_stack[:] = [ util.FastEncodingBuffer( error_template.output_encoding, error_template.encoding_errors, ) ] context._set_with_template(error_template) error_template.render_context(context, error=error)
Example #16
Source File: runtime.py From teleport with Apache License 2.0 | 6 votes |
def _render_error(template, context, error): if template.error_handler: result = template.error_handler(context, error) if not result: compat.reraise(*sys.exc_info()) else: error_template = exceptions.html_error_template() if context._outputting_as_unicode: context._buffer_stack[:] = [ util.FastEncodingBuffer(as_unicode=True) ] else: context._buffer_stack[:] = [ util.FastEncodingBuffer( error_template.output_encoding, error_template.encoding_errors, ) ] context._set_with_template(error_template) error_template.render_context(context, error=error)
Example #17
Source File: runtime.py From mako with MIT License | 6 votes |
def _render_error(template, context, error): if template.error_handler: result = template.error_handler(context, error) if not result: compat.reraise(*sys.exc_info()) else: error_template = exceptions.html_error_template() if context._outputting_as_unicode: context._buffer_stack[:] = [ util.FastEncodingBuffer(as_unicode=True) ] else: context._buffer_stack[:] = [ util.FastEncodingBuffer( error_template.output_encoding, error_template.encoding_errors, ) ] context._set_with_template(error_template) error_template.render_context(context, error=error)
Example #18
Source File: test_exceptions.py From mako with MIT License | 5 votes |
def test_py_unicode_error_html_error_template(self): try: raise RuntimeError(u("日本")) except: html_error = exceptions.html_error_template().render() assert ( u("RuntimeError: 日本").encode("ascii", "ignore") in html_error )
Example #19
Source File: test_exceptions.py From docassemble with MIT License | 5 votes |
def test_tback_trace_from_py_file(self): t = self._file_template("runtimeerr.html") try: t.render() assert False except: html_error = exceptions.html_error_template().\ render_unicode() assert "local variable 'y' referenced before assignment" in html_error
Example #20
Source File: test_exceptions.py From docassemble with MIT License | 5 votes |
def test_tback_no_trace_from_py_file(self): try: t = self._file_template("runtimeerr.html") t.render() except: t, v, tback = sys.exc_info() if not compat.py3k: # blow away tracebaack info sys.exc_clear() # and don't even send what we have. html_error = exceptions.html_error_template().\ render_unicode(error=v, traceback=None) assert "local variable 'y' referenced before assignment" in html_error
Example #21
Source File: run_wsgi.py From mako with MIT License | 5 votes |
def serve(environ, start_response): """serves requests using the WSGI callable interface.""" fieldstorage = cgi.FieldStorage( fp = environ['wsgi.input'], environ = environ, keep_blank_values = True ) d = dict([(k, getfield(fieldstorage[k])) for k in fieldstorage]) uri = environ.get('PATH_INFO', '/') if not uri: uri = '/index.html' else: uri = re.sub(r'^/$', '/index.html', uri) if re.match(r'.*\.html$', uri): try: template = lookup.get_template(uri) except exceptions.TopLevelLookupException: start_response("404 Not Found", []) return [str.encode("Cant find template '%s'" % uri)] start_response("200 OK", [('Content-type','text/html')]) try: return [template.render(**d)] except: return [exceptions.html_error_template().render()] else: u = re.sub(r'^\/+', '', uri) filename = os.path.join(root, u) if os.path.isfile(filename): start_response("200 OK", [('Content-type',guess_type(uri))]) return [open(filename, 'rb').read()] else: start_response("404 Not Found", []) return [str.encode("File not found: '%s'" % filename)]
Example #22
Source File: test_exceptions.py From docassemble with MIT License | 5 votes |
def test_py_unicode_error_html_error_template(self): try: raise RuntimeError(u('日本')) except: html_error = exceptions.html_error_template().render() assert u("RuntimeError: 日本").encode('ascii', 'ignore') in html_error
Example #23
Source File: test_exceptions.py From docassemble with MIT License | 5 votes |
def test_format_closures(self): try: exec("def foo():"\ " raise RuntimeError('test')", locals()) foo() except: html_error = exceptions.html_error_template().render() assert "RuntimeError: test" in str(html_error)
Example #24
Source File: test_exceptions.py From docassemble with MIT License | 5 votes |
def test_html_error_template(self): """test the html_error_template""" code = """ % i = 0 """ try: template = Template(code) template.render_unicode() assert False except exceptions.CompileException: html_error = exceptions.html_error_template().render_unicode() assert ("CompileException: Fragment 'i = 0' is not " "a partial control statement at line: 2 char: 1") in html_error assert '<style>' in html_error html_error_stripped = html_error.strip() assert html_error_stripped.startswith('<html>') assert html_error_stripped.endswith('</html>') not_full = exceptions.html_error_template().\ render_unicode(full=False) assert '<html>' not in not_full assert '<style>' in not_full no_css = exceptions.html_error_template().\ render_unicode(css=False) assert '<style>' not in no_css else: assert False, ("This function should trigger a CompileException, " "but didn't")
Example #25
Source File: run_wsgi.py From docassemble with MIT License | 5 votes |
def serve(environ, start_response): """serves requests using the WSGI callable interface.""" fieldstorage = cgi.FieldStorage( fp = environ['wsgi.input'], environ = environ, keep_blank_values = True ) d = dict([(k, getfield(fieldstorage[k])) for k in fieldstorage]) uri = environ.get('PATH_INFO', '/') if not uri: uri = '/index.html' else: uri = re.sub(r'^/$', '/index.html', uri) if re.match(r'.*\.html$', uri): try: template = lookup.get_template(uri) except exceptions.TopLevelLookupException: start_response("404 Not Found", []) return [str.encode("Cant find template '%s'" % uri)] start_response("200 OK", [('Content-type','text/html')]) try: return [template.render(**d)] except: return [exceptions.html_error_template().render()] else: u = re.sub(r'^\/+', '', uri) filename = os.path.join(root, u) if os.path.isfile(filename): start_response("200 OK", [('Content-type',guess_type(uri))]) return [open(filename, 'rb').read()] else: start_response("404 Not Found", []) return [str.encode("File not found: '%s'" % filename)]
Example #26
Source File: gazee.py From gazee with GNU General Public License v3.0 | 5 votes |
def serve_template(templatename, **kwargs): html_dir = 'public/html/' _hplookup = TemplateLookup(directories=[html_dir]) try: template = _hplookup.get_template(templatename) return template.render(**kwargs) except: return exceptions.html_error_template().render()
Example #27
Source File: test_template.py From mako with MIT License | 5 votes |
def test_escapes_html_tags(self): from mako.exceptions import html_error_template x = Template( """ X: <% raise Exception('<span style="color:red">Foobar</span>') %> """ ) try: x.render() except: # <h3>Exception: <span style="color:red">Foobar</span></h3> markup = html_error_template().render(full=False, css=False) if compat.py3k: assert ( '<span style="color:red">Foobar</span></h3>'.encode( "ascii" ) not in markup ) assert ( "<span style="color:red"" ">Foobar</span>".encode("ascii") in markup ) else: assert ( '<span style="color:red">Foobar</span></h3>' not in markup ) assert ( "<span style="color:red"" ">Foobar</span>" in markup )
Example #28
Source File: test_exceptions.py From mako with MIT License | 5 votes |
def test_html_error_template(self): """test the html_error_template""" code = """ % i = 0 """ try: template = Template(code) template.render_unicode() assert False except exceptions.CompileException: html_error = exceptions.html_error_template().render_unicode() assert ( "CompileException: Fragment 'i = 0' is not " "a partial control statement at line: 2 char: 1" ) in html_error assert "<style>" in html_error html_error_stripped = html_error.strip() assert html_error_stripped.startswith("<html>") assert html_error_stripped.endswith("</html>") not_full = exceptions.html_error_template().render_unicode( full=False ) assert "<html>" not in not_full assert "<style>" in not_full no_css = exceptions.html_error_template().render_unicode(css=False) assert "<style>" not in no_css else: assert False, ( "This function should trigger a CompileException, " "but didn't" )
Example #29
Source File: test_exceptions.py From mako with MIT License | 5 votes |
def test_mod_no_encoding(self): mod = __import__("test.foo.mod_no_encoding").foo.mod_no_encoding try: mod.run() except: t, v, tback = sys.exc_info() exceptions.html_error_template().render_unicode( error=v, traceback=tback )
Example #30
Source File: test_exceptions.py From docassemble with MIT License | 4 votes |
def test_utf8_html_error_template_no_pygments(self): """test the html_error_template with a Template containing UTF-8 chars""" if compat.py3k: code = """# -*- coding: utf-8 -*- % if 2 == 2: /an error ${'привет'} % endif """ else: code = """# -*- coding: utf-8 -*- % if 2 == 2: /an error ${u'привет'} % endif """ try: template = Template(code) template.render_unicode() except exceptions.CompileException: html_error = exceptions.html_error_template().render() if compat.py3k: assert ("CompileException: Fragment 'if 2 == 2: /an " "error' is not a partial control statement " "at line: 2 char: 1").encode(sys.getdefaultencoding(), 'htmlentityreplace') in \ html_error else: assert ("CompileException: Fragment 'if 2 == 2: /an " "error' is not a partial control statement " "at line: 2 char: 1") in \ html_error if compat.py3k: assert "${'привет'}".encode(sys.getdefaultencoding(), 'htmlentityreplace') in html_error else: assert u("${u'привет'}").encode(sys.getdefaultencoding(), 'htmlentityreplace') in html_error else: assert False, ("This function should trigger a CompileException, " "but didn't")