Merge pull request #152 from sergei-maertens/master
Refs. #151 -- detect binary payloads and send the correct opcode
This commit is contained in:
commit
a25f49eb41
@ -133,7 +133,16 @@ class WSClient:
|
||||
|
||||
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)
|
||||
|
||||
def peek_stdout(self, timeout=0):
|
||||
"""Same as peek_channel with channel=1."""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user