[pypy-commit] pypy win32-cleanup2: raise correct error for invalid fd
mattip
noreply at buildbot.pypy.org
Fri Apr 20 14:02:17 CEST 2012
Author: Matti Picus <matti.picus at gmail.com>
Branch: win32-cleanup2
Changeset: r54575:e7ce29040264
Date: 2012-04-20 15:01 +0300
http://bitbucket.org/pypy/pypy/changeset/e7ce29040264/
Log: raise correct error for invalid fd
diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -5,6 +5,7 @@
from pypy.rlib import streamio
from pypy.rlib.rarithmetic import r_longlong
from pypy.rlib.rstring import StringBuilder
+from pypy.rlib.rposix import validate_fd
from pypy.module._file.interp_stream import W_AbstractStream, StreamErrors
from pypy.module.posix.interp_posix import dispatch_filename
from pypy.interpreter.error import OperationError, operationerrfmt
@@ -271,6 +272,15 @@
def file_fdopen(self, fd, mode="r", buffering=-1):
try:
+ # Catch invalid fd early to get an OSError rather than an
+ # IOError from streamio
+ validate_fd(fd)
+ except OSError, e:
+ w_error = self.space.call_function(self.space.w_OSError,
+ self.space.wrap(e.errno), self.space.wrap(e.strerror),
+ self.space.wrap(e.filename))
+ raise OperationError(self.space.w_OSError, w_error)
+ try:
self.direct_fdopen(fd, mode, buffering)
except StreamErrors, e:
raise wrap_streamerror(self.space, e, self.w_name)
More information about the pypy-commit
mailing list