X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;ds=inline;f=wrw%2Fresp.py;h=24896bab3b0512bfef2cf7c408586fa41caffbaa;hb=d99a17a601c0680a325338189e6eeac0eb7d7bce;hp=8216d23502d9386b674bb304e36729442b6cf99a;hpb=4bd573f957065c9a1998b3c7202892319a004c95;p=wrw.git diff --git a/wrw/resp.py b/wrw/resp.py index 8216d23..24896ba 100644 --- a/wrw/resp.py +++ b/wrw/resp.py @@ -1,66 +1,56 @@ -import dispatch, proto +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 """ - - -
-%s - - -%s - -""" % (self.head(title), content) + def page(self, req, title, *content): + return xhtml.forreq(req, h.html(self.head(req, title), h.body(*content))) - def head(self, title): - return """%s
\n""" % (message, detail)) + def message(self, req, message, *detail): + return self.page(req, message, h.h1(message), h.p(*detail)) - def message(self, message, detail): - return self.page(message, """%s
\n""" % (message, detail)) - -defskel = skeleton() +defskel = env.var(skeleton()) def getskel(req): - return [defskel] + return [defskel.val] def skelfor(req): return req.item(getskel)[0] def setskel(req, skel): 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 skelfor(req).error(req, self.message, *self.detail) class message(dispatch.restart): - def __init__(self, message, detail): + def __init__(self, msg, *detail): super(message, self).__init__() - self.message = message + self.message = msg self.detail = detail def handle(self, req): - return [skelfor(req).message(self.message, self.detail)] + return skelfor(req).error(req, 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):