Merge branch 'master' into python3
[wrw.git] / wrw / proto.py
index 4cf1951..96a8878 100644 (file)
@@ -98,13 +98,15 @@ def simpleerror(env, startreq, code, title, msg):
 </body>
 </html>
 """ % (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 = ""
+    invalid = "&=#?/\"'"
     for c in url:
-        if c == "&" or c == "=" or c == "#" or c == "?" or c == "/" or (ord(c) <= 32):
+        if c in invalid or (ord(c) <= 32):
             ret += "%%%02X" % ord(c)
         else:
             ret += c