From c5b5a6ad1bcb55369b9ddb0a0f0637965403f214 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Tue, 17 May 2011 23:13:36 -0700 Subject: [PATCH] Fix websocket after string type changes introduced by python3 merge --- tornado/websocket.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tornado/websocket.py b/tornado/websocket.py index 696a178d..1170cff8 100644 --- a/tornado/websocket.py +++ b/tornado/websocket.py @@ -87,7 +87,7 @@ class WebSocketHandler(tornado.web.RequestHandler): # This is necessary when using proxies (such as HAProxy), which # need to see the Upgrade headers before passing through the # non-HTTP traffic that follows. - self.stream.write( + self.stream.write(tornado.escape.utf8( "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" "Upgrade: WebSocket\r\n" "Connection: Upgrade\r\n" @@ -98,7 +98,7 @@ class WebSocketHandler(tornado.web.RequestHandler): origin=self.request.headers["Origin"], scheme=scheme, host=self.request.host, - uri=self.request.uri))) + uri=self.request.uri)))) self.stream.read_bytes(8, self._handle_challenge) def _handle_challenge(self, challenge): @@ -259,9 +259,10 @@ class WebSocketRequest(object): """Processes the key headers and calculates their key value. Raises ValueError when feed invalid key.""" - number, spaces = filter(str.isdigit, key), filter(str.isspace, key) + number = int(''.join(c for c in key if c.isdigit())) + spaces = len([c for c in key if c.isspace()]) try: - key_number = int(number) / len(spaces) + key_number = number / spaces except (ValueError, ZeroDivisionError): raise ValueError return struct.pack(">I", key_number)