From ef04ec8791734c918a5b8940976bf3fde3618710 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Sun, 13 May 2012 04:42:23 +0200 Subject: [PATCH] Use SP for all wrw.resp. --- wrw/resp.py | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/wrw/resp.py b/wrw/resp.py index 3514616..9ad22d1 100644 --- a/wrw/resp.py +++ b/wrw/resp.py @@ -1,31 +1,21 @@ 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(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): -- 2.11.0