summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2014-08-03 21:34:38 +0000
committercliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2014-08-03 21:34:38 +0000
commit1355dcb2daf8f6e9b2a41688d06f1b72044dc400 (patch)
tree9bc4b332411573d59ed07e423224009e85911f4c
parentc2249618e6316429f3fc3fd8ba4d39190047ce24 (diff)
downloadpyserial-1355dcb2daf8f6e9b2a41688d06f1b72044dc400.tar.gz
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
-rw-r--r--serial/serialposix.py10
1 files 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):