Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit a25f49e

Browse files
authored
Merge pull request #152 from sergei-maertens/master
Refs. #151 -- detect binary payloads and send the correct opcode
2 parents 7ea5cb4 + 3827074 commit a25f49e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

stream/ws_client.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,16 @@ def readline_channel(self, channel, timeout=None):
133133

134134
def write_channel(self, channel, data):
135135
"""Write data to a channel."""
136-
self.sock.send(chr(channel) + data)
136+
# check if we're writing binary data or not
137+
binary = six.PY3 and type(data) == six.binary_type
138+
opcode = ABNF.OPCODE_BINARY if binary else ABNF.OPCODE_TEXT
139+
140+
channel_prefix = chr(channel)
141+
if binary:
142+
channel_prefix = six.binary_type(channel_prefix, "ascii")
143+
144+
payload = channel_prefix + data
145+
self.sock.send(payload, opcode=opcode)
137146

138147
def peek_stdout(self, timeout=0):
139148
"""Same as peek_channel with channel=1."""

0 commit comments

Comments
 (0)