3 __all__ = ["skeleton", "skelfor", "setskel", "usererror"]
5 class skeleton(object):
6 def page(self, title, content):
7 return """<?xml version="1.0" ?>
8 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
9 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
16 </html>""" % (self.head(title), content)
18 def head(self, title):
19 return """<title>%s</title>\n%s""" % (title, self.style())
24 def error(self, message, detail):
25 return self.page(message, """<h1>%s</h1>\n<p>%s</p>\n""" % (message, detail))
27 def message(self, message, detail):
28 return self.page(message, """<h1>%s</h1>\n<p>%s</p>\n""" % (message, detail))
35 return req.item(getskel)[0]
36 def setskel(req, skel):
37 req.item(getskel)[0] = skel
39 class usererror(dispatch.restart):
40 def __init__(self, message, detail):
41 super(usererror, self).__init__()
42 self.message = message
45 def handle(self, req):
46 return [skelfor(req).error(self.message, self.detail)]
48 class message(dispatch.restart):
49 def __init__(self, message, detail):
50 super(message, self).__init__()
51 self.message = message
54 def handle(self, req):
55 return [skelfor(req).message(self.message, self.detail)]
57 class httperror(usererror):
58 def __init__(self, status, message = None, detail = None):
60 message = proto.statusinfo[status][0]
62 detail = proto.statusinfo[status][1]
63 super(httperror, self).__init__(message, detail)
66 def handle(self, req):
67 req.status(self.status, self.message)
68 return super(httperror, self).handle(req)
70 class notfound(httperror):
72 return super(notfound, self).__init__(404)
74 class redirect(dispatch.restart):
75 def __init__(self, url, status = 303):
76 super(redirect, self).__init__()
80 def handle(self, req):
81 req.status(self.status, "Redirect")
82 req.ohead["Location"] = proto.appendurl(proto.requrl(req), self.url)