X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fproto.py;h=4cf19519bb739832d841defe522ae5a49f80ec6a;hb=d22f3483df089fc239b4182807c12aaab5ab1c7d;hp=3d8b96e6f22e1afb91992dafd3a3ba03a0faf6d8;hpb=e21c438203ce0654499264e31bd673ee924e6254;p=wrw.git diff --git a/wrw/proto.py b/wrw/proto.py index 3d8b96e..4cf1951 100644 --- a/wrw/proto.py +++ b/wrw/proto.py @@ -1,3 +1,5 @@ +import time + statusinfo = { 400: ("Bad Request", "Invalid HTTP request."), 401: ("Unauthorized", "Authentication must be provided for the requested resource."), @@ -83,6 +85,22 @@ def htmlq(html): ret += c return ret +def simpleerror(env, startreq, code, title, msg): + buf = """ + + + +%s + + +

%s

+

%s

+ + +""" % (title, title, htmlq(msg)) + startreq("%i %s" % (code, title), [("Content-Type", "text/html"), ("Content-Length", str(len(buf)))]) + return [buf] + def urlq(url): ret = "" for c in url: @@ -131,16 +149,26 @@ def appendurl(url, other): p = local.rfind('/') return consurl(proto, host, local[:p + 1] + other) -def requrl(req): +def siteurl(req): host = req.ihead.get("Host", None) if host is None: raise Exception("Could not reconstruct URL because no Host header was sent") proto = "http" if req.https: proto = "https" + return "%s://%s/" % (proto, host) + +def scripturl(req): + s = siteurl(req) + if req.uriname[0] != '/': + raise Exception("Malformed local part when reconstructing URL") + return siteurl(req) + req.uriname[1:] + +def requrl(req): + s = siteurl(req) if req.uri[0] != '/': raise Exception("Malformed local part when reconstructing URL") - return "%s://%s%s" % (proto, host, req.uri) + return siteurl(req) + req.uri[1:] def parstring(pars={}, **augment): buf = ""