2
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
3
# See LICENSE for details.
6
"""I am the Twisted.Web error resources and exceptions."""
11
from twisted.web import http
13
class Error(Exception):
14
def __init__(self, code, message = None, response = None):
15
message = message or http.responses.get(code)
16
Exception.__init__(self, code, message, response)
18
self.response = response
21
return '%s %s' % (self[0], self[1])
23
class PageRedirect(Error):
24
"""A request that resulted in a http redirect """
25
def __init__(self, code, message = None, response = None, location = None):
26
message = message or ("%s to %s" % (http.responses.get(code), location))
27
Error.__init__(self, code, message, response)
28
self.location = location
30
class ErrorPage(resource.Resource):
31
def __init__(self, status, brief, detail):
32
resource.Resource.__init__(self)
37
def render(self, request):
38
request.setResponseCode(self.code)
39
request.setHeader("content-type", "text/html")
41
<head><title>%s - %s</title></head>
44
</body></html>\n\n""" %
45
(self.code, self.brief, self.brief, self.detail))
47
def getChild(self, chnam, request):
51
class NoResource(ErrorPage):
52
def __init__(self, message="Sorry. No luck finding that resource."):
53
ErrorPage.__init__(self, http.NOT_FOUND,
57
class ForbiddenResource(ErrorPage):
58
def __init__(self, message="Sorry, resource is forbidden."):
59
ErrorPage.__init__(self, http.FORBIDDEN,