[Jython-checkins] jython: Set seekable=false when seek() raises IOError

darjus.loktevic jython-checkins at python.org
Sun Nov 15 19:56:16 EST 2015


https://hg.python.org/jython/rev/fc33f0456a64
changeset:   7810:fc33f0456a64
parent:      7808:ca32babcd1ee
user:        Stephen Drake <steve at synergyconsultingnz.com>
date:        Sat Nov 14 21:15:37 2015 +1100
summary:
  Set seekable=false when seek() raises IOError
If a file is not seekable, seekable() should return False rather than raise
IOError.  See https://docs.python.org/2/library/io.html#i-o-base-classes

files:
  src/org/python/modules/_io/PyFileIO.java |  10 +++++++++-
  1 files changed, 9 insertions(+), 1 deletions(-)


diff --git a/src/org/python/modules/_io/PyFileIO.java b/src/org/python/modules/_io/PyFileIO.java
--- a/src/org/python/modules/_io/PyFileIO.java
+++ b/src/org/python/modules/_io/PyFileIO.java
@@ -392,7 +392,15 @@
             throw closedValueError();
         }
         if (!seekableKnown) {
-            seekable = ioDelegate.seek(0, 1) >= 0;  // Trial seek
+            try {
+                ioDelegate.seek(0, 1);  // Trial seek
+                seekable = true;
+            } catch (PyException exc) {
+                if (!exc.match(Py.IOError)) {
+                    throw exc;
+                }
+                seekable = false;
+            }
             seekableKnown = true;
         }
         return seekable;

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list