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

Refs. #151 -- detect binary payloads and send the correct opcode #152

Merged
merged 1 commit into from
Feb 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion stream/ws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,16 @@ def readline_channel(self, channel, timeout=None):

def write_channel(self, channel, data):
"""Write data to a channel."""
self.sock.send(chr(channel) + data)
# check if we're writing binary data or not
binary = six.PY3 and type(data) == six.binary_type
opcode = ABNF.OPCODE_BINARY if binary else ABNF.OPCODE_TEXT

channel_prefix = chr(channel)
if binary:
channel_prefix = six.binary_type(channel_prefix, "ascii")

payload = channel_prefix + data
self.sock.send(payload, opcode=opcode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test case here that writes binary data?


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