Merge branch 'master' into python3
[wrw.git] / wrw / proto.py
index 8c8dcee..0e49379 100644 (file)
@@ -98,14 +98,17 @@ 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):
+    if isinstance(url, unicode):
+        url = url.encode("utf-8")
     ret = ""
     invalid = "&=#?/\"'"
     for c in url:
-        if c in invalid or (ord(c) <= 32):
+        if c in invalid or (ord(c) <= 32) or (ord(c) >= 128):
             ret += "%%%02X" % ord(c)
         else:
             ret += c