import dispatch, proto, env
+from sp import xhtml
+h = xhtml.cons()
__all__ = ["skeleton", "skelfor", "setskel", "usererror"]
class skeleton(object):
- def page(self, title, content):
- return """<?xml version="1.0" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
-<head>
-%s
-</head>
-<body>
-%s
-</body>
-</html>""" % (self.head(title), content)
+ def page(self, title, *content):
+ return h.html(self.head(title), h.body(*content))
def head(self, title):
- return """<title>%s</title>\n%s""" % (title, self.style())
+ return xhtml.head(title=title)
- def style(self):
- return ""
+ def error(self, message, *detail):
+ return self.page(message, h.h1(message), h.p(*detail))
- def error(self, message, detail):
- return self.page(message, """<h1>%s</h1>\n<p>%s</p>\n""" % (message, detail))
-
- def message(self, message, detail):
- return self.page(message, """<h1>%s</h1>\n<p>%s</p>\n""" % (message, detail))
+ def message(self, message, *detail):
+ return self.page(message, h.h1(message), h.p(*detail))
defskel = env.var(skeleton())
req.item(getskel)[0] = skel
class usererror(dispatch.restart):
- def __init__(self, message, detail):
+ def __init__(self, message, *detail):
super(usererror, self).__init__()
self.message = message
self.detail = detail
def handle(self, req):
- return [skelfor(req).error(self.message, self.detail)]
+ return xhtml.forreq(req, skelfor(req).error(self.message, *self.detail))
class message(dispatch.restart):
- def __init__(self, msg, detail):
+ def __init__(self, msg, *detail):
super(message, self).__init__()
self.message = msg
self.detail = detail
def handle(self, req):
- return [skelfor(req).message(self.message, self.detail)]
+ return xhtml.forreq(req, skelfor(req).error(self.message, *self.detail))
class httperror(usererror):
def __init__(self, status, message = None, detail = None):
if message is None:
message = proto.statusinfo[status][0]
if detail is None:
- detail = proto.statusinfo[status][1]
- super(httperror, self).__init__(message, detail)
+ detail = (proto.statusinfo[status][1],)
+ super(httperror, self).__init__(message, *detail)
self.status = status
def handle(self, req):