X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fproto.py;h=cc2edb85d5665046395fd42566efe1ea28f0d220;hb=11c9628ee0bad3e74e60b040986edc59465f4675;hp=4cf19519bb739832d841defe522ae5a49f80ec6a;hpb=10ba659d32518d2d09b12ada86a380798b378fe7;p=wrw.git diff --git a/wrw/proto.py b/wrw/proto.py index 4cf1951..cc2edb8 100644 --- a/wrw/proto.py +++ b/wrw/proto.py @@ -98,16 +98,20 @@ def simpleerror(env, startreq, code, title, msg): """ % (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):