assert that data read/written on the receiver handle is of type bytes
This commit is contained in:
parent
7d440c2430
commit
a0a76f738b
|
|
@ -215,6 +215,8 @@ def write(device_handle, data):
|
||||||
the Control Endpoint (Endpoint 0).
|
the Control Endpoint (Endpoint 0).
|
||||||
"""
|
"""
|
||||||
assert device_handle
|
assert device_handle
|
||||||
|
assert data
|
||||||
|
assert isinstance(data, bytes), (repr(data), type(data))
|
||||||
bytes_written = _os.write(device_handle, data)
|
bytes_written = _os.write(device_handle, data)
|
||||||
if bytes_written != len(data):
|
if bytes_written != len(data):
|
||||||
raise IOError(_errno.EIO, 'written %d bytes out of expected %d' % (bytes_written, len(data)))
|
raise IOError(_errno.EIO, 'written %d bytes out of expected %d' % (bytes_written, len(data)))
|
||||||
|
|
@ -248,6 +250,7 @@ def read(device_handle, bytes_count, timeout_ms=-1):
|
||||||
assert rlist == [device_handle]
|
assert rlist == [device_handle]
|
||||||
data = _os.read(device_handle, bytes_count)
|
data = _os.read(device_handle, bytes_count)
|
||||||
assert data is not None
|
assert data is not None
|
||||||
|
assert isinstance(data, bytes), (repr(data), type(data))
|
||||||
return data
|
return data
|
||||||
else:
|
else:
|
||||||
return b''
|
return b''
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,9 @@ def write(handle, devnumber, data):
|
||||||
unloaded. The handle will be closed automatically.
|
unloaded. The handle will be closed automatically.
|
||||||
"""
|
"""
|
||||||
# the data is padded to either 5 or 18 bytes
|
# the data is padded to either 5 or 18 bytes
|
||||||
|
assert data is not None
|
||||||
|
assert isinstance(data, bytes), (repr(data), type(data))
|
||||||
|
|
||||||
if len(data) > _SHORT_MESSAGE_SIZE - 2 or data[:1] == b'\x82':
|
if len(data) > _SHORT_MESSAGE_SIZE - 2 or data[:1] == b'\x82':
|
||||||
wdata = _pack(b'!BB18s', 0x11, devnumber, data)
|
wdata = _pack(b'!BB18s', 0x11, devnumber, data)
|
||||||
else:
|
else:
|
||||||
|
|
@ -188,6 +191,7 @@ def _read(handle, timeout):
|
||||||
raise NoReceiver(reason=reason)
|
raise NoReceiver(reason=reason)
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
|
assert isinstance(data, bytes), (repr(data), type(data))
|
||||||
report_id = ord(data[:1])
|
report_id = ord(data[:1])
|
||||||
assert (report_id == 0x10 and len(data) == _SHORT_MESSAGE_SIZE or
|
assert (report_id == 0x10 and len(data) == _SHORT_MESSAGE_SIZE or
|
||||||
report_id == 0x11 and len(data) == _LONG_MESSAGE_SIZE or
|
report_id == 0x11 and len(data) == _LONG_MESSAGE_SIZE or
|
||||||
|
|
@ -218,6 +222,7 @@ def _skip_incoming(handle, ihandle, notifications_hook):
|
||||||
raise NoReceiver(reason=reason)
|
raise NoReceiver(reason=reason)
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
|
assert isinstance(data, bytes), (repr(data), type(data))
|
||||||
if _log.isEnabledFor(_DEBUG):
|
if _log.isEnabledFor(_DEBUG):
|
||||||
report_id = ord(data[:1])
|
report_id = ord(data[:1])
|
||||||
assert (report_id == 0x10 and len(data) == _SHORT_MESSAGE_SIZE or
|
assert (report_id == 0x10 and len(data) == _SHORT_MESSAGE_SIZE or
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue