diff --git a/lib/hidapi/udev.py b/lib/hidapi/udev.py index 208636f3..65faeb53 100644 --- a/lib/hidapi/udev.py +++ b/lib/hidapi/udev.py @@ -215,6 +215,8 @@ def write(device_handle, data): the Control Endpoint (Endpoint 0). """ assert device_handle + assert data + assert isinstance(data, bytes), (repr(data), type(data)) bytes_written = _os.write(device_handle, data) if 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] data = _os.read(device_handle, bytes_count) assert data is not None + assert isinstance(data, bytes), (repr(data), type(data)) return data else: return b'' diff --git a/lib/logitech/unifying_receiver/base.py b/lib/logitech/unifying_receiver/base.py index 2e841fa8..5193c74b 100644 --- a/lib/logitech/unifying_receiver/base.py +++ b/lib/logitech/unifying_receiver/base.py @@ -141,6 +141,9 @@ def write(handle, devnumber, data): unloaded. The handle will be closed automatically. """ # 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': wdata = _pack(b'!BB18s', 0x11, devnumber, data) else: @@ -188,6 +191,7 @@ def _read(handle, timeout): raise NoReceiver(reason=reason) if data: + assert isinstance(data, bytes), (repr(data), type(data)) report_id = ord(data[:1]) assert (report_id == 0x10 and len(data) == _SHORT_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) if data: + assert isinstance(data, bytes), (repr(data), type(data)) if _log.isEnabledFor(_DEBUG): report_id = ord(data[:1]) assert (report_id == 0x10 and len(data) == _SHORT_MESSAGE_SIZE or