Fix websocket after string type changes introduced by python3 merge

This commit is contained in:
Ben Darnell 2011-05-17 23:13:36 -07:00
parent d9648660ac
commit c5b5a6ad1b
1 changed files with 5 additions and 4 deletions

View File

@ -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)