Use frombytes() instead of fromstring()

Both the Python library and NumPy have changed the names of these
functions to better match the new bytes data type it actually uses.
This commit is contained in:
Pierre Ossman 2020-12-14 16:08:16 +01:00
parent 96eda1a5c7
commit 33710b3972
1 changed files with 4 additions and 4 deletions

View File

@ -749,7 +749,7 @@ class WebSocket(object):
mask = numpy.frombuffer(mask, dtype, count=1)
data = numpy.frombuffer(buf, dtype, count=int(plen / 4))
#b = numpy.bitwise_xor(data, mask).data
b = numpy.bitwise_xor(data, mask).tostring()
b = numpy.bitwise_xor(data, mask).tobytes()
if plen % 4:
dtype=numpy.dtype('B')
@ -758,15 +758,15 @@ class WebSocket(object):
mask = numpy.frombuffer(mask, dtype, count=(plen % 4))
data = numpy.frombuffer(buf, dtype,
offset=plen - (plen % 4), count=(plen % 4))
c = numpy.bitwise_xor(data, mask).tostring()
c = numpy.bitwise_xor(data, mask).tobytes()
return b + c
else:
# Slower fallback
data = array.array('B')
data.fromstring(buf)
data.frombytes(buf)
for i in range(len(data)):
data[i] ^= mask[i % 4]
return data.tostring()
return data.tobytes()
def _encode_hybi(self, opcode, buf, mask_key=None, fin=True):
""" Encode a HyBi style WebSocket frame.