view lib/cycloneerr/cycloneerr.py @ 1329:9a881a4e4154

release 0.2.0 Ignore-this: 91607f26358303141f4ce1380002b4f5 darcs-hash:b9e790efd16d02481519b1114cb558528529fb76
author drewp <drewp@bigasterisk.com>
date Tue, 23 Apr 2019 02:12:07 -0700
parents c5bd44f90ced
children fd94061db75c
line wrap: on
line source

try:
    import http.client as httplib
except ImportError:
    import 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),
        }