X-Git-Url: http://dolda2000.com/gitweb/?p=wrw.git;a=blobdiff_plain;f=wrw%2Fresp.py;h=965df6c8c18a76e41e659f92eccf08ef57f4fe30;hp=24896bab3b0512bfef2cf7c408586fa41caffbaa;hb=5afb31180662cfaf123ae6155a832470c7c6dce2;hpb=3162cb89d51c4df9eec6c979d20bc4a2c82da5f9 diff --git a/wrw/resp.py b/wrw/resp.py index 24896ba..965df6c 100644 --- a/wrw/resp.py +++ b/wrw/resp.py @@ -1,5 +1,5 @@ -import dispatch, proto, env -from sp import xhtml +from . import dispatch, proto, env +from .sp import xhtml h = xhtml.cons() __all__ = ["skeleton", "skelfor", "setskel", "usererror"] @@ -28,7 +28,7 @@ def setskel(req, skel): class usererror(dispatch.restart): def __init__(self, message, *detail): - super(usererror, self).__init__() + super().__init__() self.message = message self.detail = detail @@ -36,38 +36,51 @@ class usererror(dispatch.restart): return skelfor(req).error(req, self.message, *self.detail) class message(dispatch.restart): - def __init__(self, msg, *detail): - super(message, self).__init__() - self.message = msg + def __init__(self, message, *detail): + super().__init__() + self.message = message self.detail = detail def handle(self, req): - return skelfor(req).error(req, 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: detail = (proto.statusinfo[status][1],) - super(httperror, self).__init__(message, *detail) + 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__() + 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 []