diff options
author | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2014-08-03 21:34:38 +0000 |
---|---|---|
committer | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2014-08-03 21:34:38 +0000 |
commit | c7cd721362bddcf8796a254487d8d10131c163a8 (patch) | |
tree | e90fa02cc38bbb023a5a6bf0bd972d73c8d7f672 | |
parent | f2f8b53f7619edff6ab32bfde0317de810b8ade4 (diff) | |
download | pyserial-git-c7cd721362bddcf8796a254487d8d10131c163a8.tar.gz |
swap "except" for Python 3.x compatibility in read()
-rw-r--r-- | pyserial/serial/serialposix.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/pyserial/serial/serialposix.py b/pyserial/serial/serialposix.py index cf40490..5c3eb5f 100644 --- a/pyserial/serial/serialposix.py +++ b/pyserial/serial/serialposix.py @@ -481,15 +481,17 @@ class PosixSerial(SerialBase): # but reading returns nothing. raise SerialException('device reports readiness to read but returned no data (device disconnected or multiple access on port?)') read.extend(buf) + except OSError, e: + # this is for Python 3.x where select.error is a subclass of OSError + # ignore EAGAIN errors. all other errors are shown + if e.errno != errno.EAGAIN: + raise SerialException('read failed: %s' % (e,)) except select.error, e: + # this is for Python 2.x # ignore EAGAIN errors. all other errors are shown # see also http://www.python.org/dev/peps/pep-3151/#select if e[0] != errno.EAGAIN: raise SerialException('read failed: %s' % (e,)) - except OSError, e: - # ignore EAGAIN errors. all other errors are shown - if e.errno != errno.EAGAIN: - raise SerialException('read failed: %s' % (e,)) return bytes(read) def write(self, data): |