Merge branch 'master' into python3
authorFredrik Tolf <fredrik@dolda2000.com>
Wed, 18 Sep 2013 04:38:31 +0000 (06:38 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Wed, 18 Sep 2013 04:38:31 +0000 (06:38 +0200)
wrw/proto.py
wrw/sp/util.py

index 96a8878..0e49379 100644 (file)
@@ -103,10 +103,12 @@ def simpleerror(env, startreq, code, title, msg):
     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
index ad99e8b..0728a7e 100644 (file)
@@ -235,5 +235,7 @@ class response(dispatch.restart):
         raise Exception("a subclass of wrw.sp.util.response must override ctype")
 
     def handle(self, req):
+        ret = self.formatter.format(self.root, doctype=self.doctype, charset=self.charset)
         req.ohead["Content-Type"] = self.ctype
-        return [self.formatter.format(self.root, doctype=self.doctype, charset=self.charset)]
+        req.ohead["Content-Length"] = len(ret)
+        return [ret]