[Twisted-web] Nevow error with unicode localization in appserver.py REVISED

Paul Reznicek maillists at ivsn.com
Fri Jan 28 01:26:09 MST 2005


REVISED:
After some other tests - there must be encoding ONLY on unicode strings,
otherwise binary file transfer fails (try nevow/examples/image_uploader)
Paul Reznicek

Necessary patch:
===================================================================
--- appserver.py (Revision 1126)
+++ appserver.py (local)
@@ -170,6 +170,9 @@
          if isinstance(html, str):
              self.write(html)
              server.Request.finish(self)
+        elif isinstance(html, unicode):
+            self.write(html.encode('utf8'))
+            server.Request.finish(self)
          elif html is errorMarker:
              ## Error webpage has already been rendered and finish called
              pass

I believe, the wsgi.py can have similar problem:
===================================================================
--- wsgi.py (Revision 1126)
+++ wsgi.py (local)
@@ -86,6 +86,8 @@
          result = p.renderHTTP(pctx)
          if isinstance(result, str):
              request.write(result)
+        elif isinstance(result, unicode):
+            request.write(result.encode('utf8'))
          else:
              ## Exhaust the generator
              list(result)



More information about the Twisted-web mailing list