Add type checking when sendning data
We use this in various ways so add an early check to make things clear in case anything is called incorrectly.
This commit is contained in:
parent
d72ace2ae6
commit
6caf23c067
|
@ -436,6 +436,9 @@ class WebSocket(object):
|
||||||
WebSocketWantWriteError can be raised if there is insufficient
|
WebSocketWantWriteError can be raised if there is insufficient
|
||||||
space in the underlying socket.
|
space in the underlying socket.
|
||||||
"""
|
"""
|
||||||
|
if not isinstance(msg, bytes):
|
||||||
|
raise TypeError
|
||||||
|
|
||||||
if not self._sent_close:
|
if not self._sent_close:
|
||||||
# Only called to flush?
|
# Only called to flush?
|
||||||
self._sendmsg(0x2, msg)
|
self._sendmsg(0x2, msg)
|
||||||
|
@ -445,10 +448,16 @@ class WebSocket(object):
|
||||||
|
|
||||||
def ping(self, data=''.encode('ascii')):
|
def ping(self, data=''.encode('ascii')):
|
||||||
"""Write a ping message to the WebSocket."""
|
"""Write a ping message to the WebSocket."""
|
||||||
|
if not isinstance(data, bytes):
|
||||||
|
raise TypeError
|
||||||
|
|
||||||
self._sendmsg(0x9, data)
|
self._sendmsg(0x9, data)
|
||||||
|
|
||||||
def pong(self, data=''.encode('ascii')):
|
def pong(self, data=''.encode('ascii')):
|
||||||
"""Write a pong message to the WebSocket."""
|
"""Write a pong message to the WebSocket."""
|
||||||
|
if not isinstance(data, bytes):
|
||||||
|
raise TypeError
|
||||||
|
|
||||||
self._sendmsg(0xA, data)
|
self._sendmsg(0xA, data)
|
||||||
|
|
||||||
def shutdown(self, how, code=1000, reason=None):
|
def shutdown(self, how, code=1000, reason=None):
|
||||||
|
|
Loading…
Reference in New Issue