Fixed incompatibilities with os module.

- os.fdopen should raise OSError, not IOError.
This commit is contained in:
amajorek
2010-03-31 20:09:14 -04:00
parent 14e4fcda89
commit b2abc8c62d
2 changed files with 9 additions and 2 deletions

View File

@@ -18,7 +18,10 @@ def fdopen(fd, *args, **kw):
Return an open file object connected to a file descriptor."""
if not isinstance(fd, int):
raise TypeError('fd should be int, not %r' % fd)
try:
return greenio.GreenPipe(fd, *args, **kw)
except IOError, e:
raise OSError(*e.args)
__original_read__ = os_orig.read
def read(fd, n):

View File

@@ -347,7 +347,11 @@ class _SocketDuckForFd(object):
raise IOError(*e.args)
def __del__(self):
try:
os.close(self._fileno)
except:
# os.close may fail if __init__ didn't complete (i.e file dscriptor passed to popen was invalid
pass
def __repr__(self):
return "%s:%d" % (self.__class__.__name__, self._fileno)