X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=wrw%2Fresp.py;h=b62ce0e4bdefe58d6473977f77c78eaadea9e223;hb=c4126c8a6fff40b684cb3332728510725b1a3738;hp=8216d23502d9386b674bb304e36729442b6cf99a;hpb=a4811d704ac8b4d97ae9af3841823ad2b56c4380;p=wrw.git diff --git a/wrw/resp.py b/wrw/resp.py index 8216d23..b62ce0e 100644 --- a/wrw/resp.py +++ b/wrw/resp.py @@ -1,79 +1,69 @@ -import dispatch, proto +from . 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): - super(usererror, self).__init__() + def __init__(self, message, *detail): + super().__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): - super(message, self).__init__() + def __init__(self, message, *detail): + super().__init__() self.message = message 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().__init__(message, *detail) self.status = status def handle(self, req): req.status(self.status, self.message) - return super(httperror, self).handle(req) + return super().handle(req) class notfound(httperror): def __init__(self): - return super(notfound, self).__init__(404) + return super().__init__(404) class redirect(dispatch.restart): def __init__(self, url, status = 303): - super(redirect, self).__init__() + super().__init__() self.url = url self.status = status