view lib/cycloneerr.py @ 447:3d51d4b63497

patchsource py3 support. might break py2 Ignore-this: e7559afeb74ffa53bf2085f78455014
author drewp@bigasterisk.com
date Thu, 18 Apr 2019 21:58:19 -0700
parents 053fd552b675
children a63549a50b3f
line wrap: on
line source

try:
    import httplib
except ImportError:
    import http.client as httplib  # type: ignore
import cgi

class PrettyErrorHandler(object):
    """
    mix-in to improve cyclone.web.RequestHandler
    """
    def get_error_html(self, status_code, **kwargs):
        try:
            tb = kwargs['exception'].getTraceback()
        except AttributeError:
            tb = ""
        return "<html><title>%(code)d: %(message)s</title>" \
               "<body>%(code)d: %(message)s<pre>%(tb)s</pre></body></html>" % {
            "code": status_code,
            "message": httplib.responses[status_code],
            "tb" : cgi.escape(tb),
        }