X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fproto.py;h=0a6a43022004d8d45e7911fc9355d4b120840604;hb=8fec8547c47c0452333972f554f328d0c8e61be2;hp=b1f0ab375e6faba741cc1dc4da86d85ba3950e0c;hpb=0d1857825b3d370a9249436f162300cc4862006c;p=wrw.git diff --git a/wrw/proto.py b/wrw/proto.py index b1f0ab3..0a6a430 100644 --- a/wrw/proto.py +++ b/wrw/proto.py @@ -85,6 +85,23 @@ def htmlq(html): ret += c return ret +def simpleerror(env, startreq, code, title, msg): + buf = """ + + + +%s + + +

%s

+

%s

+ + +""" % (title, title, htmlq(msg)) + buf = buf.encode("us-ascii") + startreq("%i %s" % (code, title), [("Content-Type", "text/html"), ("Content-Length", str(len(buf)))]) + return [buf] + def urlq(url): ret = "" for c in url: @@ -133,16 +150,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 = ""