X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fresp.py;h=75a7f3a5cd64d9addc84a5414dc10febd3d809db;hb=f9e9a7b5b192adfc7318e7f3ba0153668eef3bc1;hp=030d5ee4385a6f1a9d3e4e8f905a3f9bddfb0a7f;hpb=dc7e5d54e72fd9a22f1509df0c7bbf05f8db8924;p=wrw.git diff --git a/wrw/resp.py b/wrw/resp.py index 030d5ee..75a7f3a 100644 --- a/wrw/resp.py +++ b/wrw/resp.py @@ -1,4 +1,4 @@ -import dispatch, proto +from . import dispatch, proto __all__ = ["skeleton", "skelfor", "setskel", "usererror"] @@ -15,7 +15,7 @@ class skeleton(object): """ % (self.head(title), content) - def skel(self, title): + def head(self, title): return """%s\n%s""" % (title, self.style()) def style(self): @@ -38,7 +38,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 @@ -47,7 +47,7 @@ class usererror(dispatch.restart): class message(dispatch.restart): def __init__(self, message, detail): - super(message, self).__init__() + super().__init__() self.message = message self.detail = detail @@ -60,13 +60,24 @@ class httperror(usererror): 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) - super(httperror, self).handle(req) + return super().handle(req) class notfound(httperror): def __init__(self): - super(notfound, self).__init__(404) + return super().__init__(404) + +class redirect(dispatch.restart): + def __init__(self, url, status = 303): + super().__init__() + self.url = url + self.status = status + + def handle(self, req): + req.status(self.status, "Redirect") + req.ohead["Location"] = proto.appendurl(proto.requrl(req), self.url) + return []