From: Fredrik Tolf Date: Sun, 13 May 2012 03:43:33 +0000 (+0200) Subject: Merge branch 'master' into python3 X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=7bcaef26c590cd10955848fbf313f41c78b8d1ce;hp=dc437c45b69d2c163141c422d354f2c25936061f;p=wrw.git Merge branch 'master' into python3 Conflicts: wrw/resp.py --- diff --git a/wrw/resp.py b/wrw/resp.py index 4840799..bc8f2db 100644 --- a/wrw/resp.py +++ b/wrw/resp.py @@ -1,31 +1,21 @@ 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, title, *content): + return h.html(self.head(title), h.body(*content)) def head(self, title): - return """%s\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, """

%s

\n

%s

\n""" % (message, detail)) - - def message(self, message, detail): - return self.page(message, """

%s

\n

%s

\n""" % (message, detail)) + def message(self, message, *detail): + return self.page(message, h.h1(message), h.p(*detail)) defskel = env.var(skeleton()) @@ -37,30 +27,30 @@ def setskel(req, skel): req.item(getskel)[0] = skel class usererror(dispatch.restart): - def __init__(self, message, detail): + 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).encode("utf-8")] + return xhtml.forreq(req, skelfor(req).error(self.message, *self.detail)) class message(dispatch.restart): - def __init__(self, message, detail): + 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).encode("utf-8")] + 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().__init__(message, detail) + detail = (proto.statusinfo[status][1],) + super().__init__(message, *detail) self.status = status def handle(self, req):