]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix draft76 websocket protocol; fix websocket demo for python 3.
authorBen Darnell <ben@bendarnell.com>
Tue, 19 Mar 2013 00:52:23 +0000 (20:52 -0400)
committerBen Darnell <ben@bendarnell.com>
Tue, 19 Mar 2013 00:52:23 +0000 (20:52 -0400)
demos/websocket/chatdemo.py
tornado/websocket.py

index a62313936c0212a828f343dd0c2135a76c3af20d..92a0e14525d1f0e43039531f9d8126d84a7682b1 100755 (executable)
@@ -88,7 +88,8 @@ class ChatSocketHandler(tornado.websocket.WebSocketHandler):
             "id": str(uuid.uuid4()),
             "body": parsed["body"],
             }
-        chat["html"] = self.render_string("message.html", message=chat)
+        chat["html"] = tornado.escape.to_basestring(
+            self.render_string("message.html", message=chat))
 
         ChatSocketHandler.update_cache(chat)
         ChatSocketHandler.send_updates(chat)
index e87e7c9bf460be8424c504717a471785af68187f..aac477371d3859ff3b57673c933a8eab00b90ae3 100644 (file)
@@ -38,7 +38,7 @@ from tornado.ioloop import IOLoop
 from tornado.log import gen_log, app_log
 from tornado.netutil import Resolver
 from tornado import simple_httpclient
-from tornado.util import bytes_type
+from tornado.util import bytes_type, unicode_type
 
 try:
     xrange  # py2
@@ -392,8 +392,9 @@ class WebSocketProtocol76(WebSocketProtocol):
         """Processes the key headers and calculates their key value.
 
         Raises ValueError when feed invalid key."""
+        # pyflakes complains about variable reuse if both of these lines use 'c'
         number = int(''.join(c for c in key if c.isdigit()))
-        spaces = len(c for c in key if c.isspace())
+        spaces = len([c2 for c2 in key if c2.isspace()])
         try:
             key_number = number // spaces
         except (ValueError, ZeroDivisionError):
@@ -438,7 +439,7 @@ class WebSocketProtocol76(WebSocketProtocol):
         if binary:
             raise ValueError(
                 "Binary messages not supported by this version of websockets")
-        if isinstance(message, unicode):
+        if isinstance(message, unicode_type):
             message = message.encode("utf-8")
         assert isinstance(message, bytes_type)
         self.stream.write(b"\x00" + message + b"\xff")