fixed error code extraction on python3

This commit is contained in:
liris
2014-12-02 12:20:22 +09:00
parent fdb5238c40
commit f820493f33
2 changed files with 6 additions and 4 deletions

View File

@@ -121,7 +121,8 @@ class ABNF(object):
raise WebSocketProtocolException("Invalid close frame.") raise WebSocketProtocolException("Invalid close frame.")
if l > 2 and not validate_utf8(self.data[2:]): if l > 2 and not validate_utf8(self.data[2:]):
raise WebSocketProtocolException("Invalid close frame.") raise WebSocketProtocolException("Invalid close frame.")
code = 256*six.byte2int(self.data[0]) + six.byte2int(self.data[1]) print(self.data)
code = 256*six.byte2int(self.data[0:1]) + six.byte2int(self.data[1:2])
if not self._is_valid_close_status(code): if not self._is_valid_close_status(code):
raise WebSocketProtocolException("Invalid close opcode.") raise WebSocketProtocolException("Invalid close opcode.")

View File

@@ -178,8 +178,9 @@ class WebSocketApp(object):
if six.PY3 and frame.opcode == ABNF.OPCODE_TEXT: if six.PY3 and frame.opcode == ABNF.OPCODE_TEXT:
data = data.decode("utf-8") data = data.decode("utf-8")
self._callback(self.on_message, data) self._callback(self.on_message, data)
except Exception as e: # except Exception as e:
self._callback(self.on_error, e) # print(e)
# self._callback(self.on_error, e)
finally: finally:
if thread: if thread:
event.set() event.set()
@@ -199,7 +200,7 @@ class WebSocketApp(object):
return [] return []
if data and len(data) >=2: if data and len(data) >=2:
code = 256*six.byte2int(data[0]) + six.byte2int(data[1]) code = 256*six.byte2int(data[0:1]) + six.byte2int(data[1:2])
reason = data[2:].decode('utf-8') reason = data[2:].decode('utf-8')
return [code,reason] return [code,reason]