summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2020-09-30 14:53:19 +0200
committerPierre Ossman <ossman@cendio.se>2020-09-30 14:53:19 +0200
commit6caf23c067b68f4b7398f3c996f9317a85f04962 (patch)
tree7f4bbc671c88d9635709ddc9d192ee8612204d81
parentd72ace2ae6cbc3785401c814abbc282031bf6293 (diff)
downloadwebsockify-6caf23c067b68f4b7398f3c996f9317a85f04962.tar.gz
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.
-rw-r--r--websockify/websocket.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/websockify/websocket.py b/websockify/websocket.py
index a9f85a9..d15113b 100644
--- a/websockify/websocket.py
+++ b/websockify/websocket.py
@@ -436,6 +436,9 @@ class WebSocket(object):
WebSocketWantWriteError can be raised if there is insufficient
space in the underlying socket.
"""
+ if not isinstance(msg, bytes):
+ raise TypeError
+
if not self._sent_close:
# Only called to flush?
self._sendmsg(0x2, msg)
@@ -445,10 +448,16 @@ class WebSocket(object):
def ping(self, data=''.encode('ascii')):
"""Write a ping message to the WebSocket."""
+ if not isinstance(data, bytes):
+ raise TypeError
+
self._sendmsg(0x9, data)
def pong(self, data=''.encode('ascii')):
"""Write a pong message to the WebSocket."""
+ if not isinstance(data, bytes):
+ raise TypeError
+
self._sendmsg(0xA, data)
def shutdown(self, how, code=1000, reason=None):