From 1355dcb2daf8f6e9b2a41688d06f1b72044dc400 Mon Sep 17 00:00:00 2001 From: cliechti Date: Sun, 3 Aug 2014 21:34:38 +0000 Subject: swap "except" for Python 3.x compatibility in read() git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@503 f19166aa-fa4f-0410-85c2-fa1106f25c8a --- serial/serialposix.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/serial/serialposix.py b/serial/serialposix.py index cf40490..5c3eb5f 100644 --- a/serial/serialposix.py +++ b/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): -- cgit v1.2.1