X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fresp.py;h=965df6c8c18a76e41e659f92eccf08ef57f4fe30;hb=5afb31180662cfaf123ae6155a832470c7c6dce2;hp=bc8f2dbcc3adeead3a7bef308db9cbb3b65bd929;hpb=ab92e396057cd617b1607f437d860ff89f5780a2;p=wrw.git diff --git a/wrw/resp.py b/wrw/resp.py index bc8f2db..965df6c 100644 --- a/wrw/resp.py +++ b/wrw/resp.py @@ -5,17 +5,17 @@ h = xhtml.cons() __all__ = ["skeleton", "skelfor", "setskel", "usererror"] class skeleton(object): - def page(self, title, *content): - return h.html(self.head(title), h.body(*content)) + def page(self, req, title, *content): + return xhtml.forreq(req, h.html(self.head(req, title), h.body(*content))) - def head(self, title): + def head(self, req, title): return xhtml.head(title=title) - def error(self, message, *detail): - return self.page(message, h.h1(message), h.p(*detail)) + def error(self, req, message, *detail): + return self.page(req, message, h.h1(message), h.p(*detail)) - def message(self, message, *detail): - return self.page(message, h.h1(message), h.p(*detail)) + def message(self, req, message, *detail): + return self.page(req, message, h.h1(message), h.p(*detail)) defskel = env.var(skeleton()) @@ -33,7 +33,7 @@ class usererror(dispatch.restart): self.detail = detail def handle(self, req): - return xhtml.forreq(req, 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): @@ -42,10 +42,10 @@ class message(dispatch.restart): self.detail = detail def handle(self, req): - return xhtml.forreq(req, skelfor(req).error(self.message, *self.detail)) + return skelfor(req).message(req, self.message, *self.detail) class httperror(usererror): - def __init__(self, status, message = None, detail = None): + def __init__(self, status, message=None, detail=None): if message is None: message = proto.statusinfo[status][0] if detail is None: @@ -62,12 +62,25 @@ class notfound(httperror): return super().__init__(404) class redirect(dispatch.restart): - def __init__(self, url, status = 303): + bases = {"url": proto.requrl, + "script": proto.scripturl, + "site": proto.siteurl} + + def __init__(self, url, status=303, base="url"): super().__init__() self.url = url self.status = status + self.bases[base] + self.base = base def handle(self, req): req.status(self.status, "Redirect") - req.ohead["Location"] = proto.appendurl(proto.requrl(req), self.url) + req.ohead["Location"] = proto.appendurl(self.bases[self.base](req), self.url) + req.ohead["Content-Length"] = 0 + return [] + +class unmodified(dispatch.restart): + def handle(self, req): + req.status(304, "Not Modified") + req.ohead["Content-Length"] = "0" return []