annotate lib/cycloneerr/cycloneerr.py @ 769:71e8ab109f5a

py3 Ignore-this: fd41253efc73d29e56aa5c3b0f2fb34f
author drewp@bigasterisk.com
date Thu, 14 May 2020 22:29:44 -0700
parents 11e090ba2731
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
430
053fd552b675 some py3
drewp@bigasterisk.com
parents: 4
diff changeset
1 try:
472
a63549a50b3f py3 protection
drewp@bigasterisk.com
parents: 447
diff changeset
2 import http.client as httplib
430
053fd552b675 some py3
drewp@bigasterisk.com
parents: 4
diff changeset
3 except ImportError:
472
a63549a50b3f py3 protection
drewp@bigasterisk.com
parents: 447
diff changeset
4 import httplib # type: ignore
769
drewp@bigasterisk.com
parents: 512
diff changeset
5 import html
4
be855a111619 move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
diff changeset
6
be855a111619 move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
diff changeset
7 class PrettyErrorHandler(object):
be855a111619 move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
diff changeset
8 """
be855a111619 move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
diff changeset
9 mix-in to improve cyclone.web.RequestHandler
be855a111619 move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
diff changeset
10 """
be855a111619 move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
diff changeset
11 def get_error_html(self, status_code, **kwargs):
be855a111619 move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
diff changeset
12 try:
be855a111619 move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
diff changeset
13 tb = kwargs['exception'].getTraceback()
be855a111619 move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
diff changeset
14 except AttributeError:
be855a111619 move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
diff changeset
15 tb = ""
be855a111619 move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
diff changeset
16 return "<html><title>%(code)d: %(message)s</title>" \
be855a111619 move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
diff changeset
17 "<body>%(code)d: %(message)s<pre>%(tb)s</pre></body></html>" % {
be855a111619 move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
diff changeset
18 "code": status_code,
be855a111619 move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
diff changeset
19 "message": httplib.responses[status_code],
769
drewp@bigasterisk.com
parents: 512
diff changeset
20 "tb" : html.escape(tb),
4
be855a111619 move a bunch of services into this tree, give them all web status pages
drewp@bigasterisk.com
parents:
diff changeset
21 }