diff --git a/alarmdecoder/util.py b/alarmdecoder/util.py index 902b21d..2702a13 100644 --- a/alarmdecoder/util.py +++ b/alarmdecoder/util.py @@ -97,7 +97,10 @@ def filter_ad2prot_byte(buf): """ Return the byte sent in back if valid visible terminal characters or line terminators. """ - c = buf[0] + if sys.version_info > (3,): + c = buf[0] + else: + c = ord(buf) if (c == 10 or c == 13): return buf diff --git a/test/test_devices.py b/test/test_devices.py index 17cba61..d418780 100644 --- a/test/test_devices.py +++ b/test/test_devices.py @@ -80,8 +80,11 @@ class TestSerialDevice(TestCase): def test_read(self): self._device.interface = '/dev/ttyS0' self._device.open(no_reader_thread=True) + side_effect = ["t"] + if sys.version_info > (3,): + side_effect = ["t".encode('utf-8')] - with patch.object(self._device._device, 'read', return_value=[1]) as mock: + with patch.object(self._device._device, 'read', side_effect=side_effect) as mock: with patch('serial.Serial.fileno', return_value=1): with patch.object(select, 'select', return_value=[[1], [], []]): ret = self._device.read()