X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fproto.py;h=cc2edb85d5665046395fd42566efe1ea28f0d220;hb=11c9628ee0bad3e74e60b040986edc59465f4675;hp=8474b3a16e533b2d1cf702d1f7e5ab40eb07a1e7;hpb=31d48e693453899e96b19ce14acab633d26fcf0b;p=wrw.git diff --git a/wrw/proto.py b/wrw/proto.py index 8474b3a..cc2edb8 100644 --- a/wrw/proto.py +++ b/wrw/proto.py @@ -85,13 +85,33 @@ 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): + if isinstance(url, str): + url = url.encode("utf-8") ret = "" + invalid = b"&=#?/\"'" for c in url: - if c == "&" or c == "=" or c == "#" or c == "?" or c == "/" or (ord(c) <= 32): - ret += "%%%02X" % ord(c) + if c in invalid or (c <= 32) or (c >= 128): + ret += "%%%02X" % c else: - ret += c + ret += chr(c) return ret class urlerror(ValueError):