diff options
author | Guido van Rossum <guido@python.org> | 2001-08-18 01:23:20 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-08-18 01:23:20 (GMT) |
commit | e5e50591a477f90203219898e02a603ba6a9d71b (patch) | |
tree | a69c6961d5734146b808b6de75219d1be81e5047 /Lib/socket.py | |
parent | 241d69c11babc3641825fa9be4dee426652f8c40 (diff) | |
download | cpython-e5e50591a477f90203219898e02a603ba6a9d71b.zip cpython-e5e50591a477f90203219898e02a603ba6a9d71b.tar.gz cpython-e5e50591a477f90203219898e02a603ba6a9d71b.tar.bz2 |
When the socket is closed, don't just assign 0 to self._sock.
This breaks software that excepts a socket.error but not an
AttributeError.
Diffstat (limited to 'Lib/socket.py')
-rw-r--r-- | Lib/socket.py | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/Lib/socket.py b/Lib/socket.py index d0f0911..ce72b65 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -122,13 +122,18 @@ def getfqdn(name=''): # These are not actually used on other platforms. # +_socketmethods = ( + 'bind', 'connect', 'connect_ex', 'fileno', 'listen', + 'getpeername', 'getsockname', 'getsockopt', 'setsockopt', + 'recv', 'recvfrom', 'send', 'sendto', 'setblocking', 'shutdown') + class _socketobject: def __init__(self, sock): self._sock = sock def close(self): - self._sock = 0 + self._sock = _closedsocket() def __del__(self): self.close() @@ -143,16 +148,21 @@ class _socketobject: def makefile(self, mode='r', bufsize=-1): return _fileobject(self._sock, mode, bufsize) - _s = "def %s(self, *args): return apply(self._sock.%s, args)\n\n" - for _m in ('bind', 'connect', 'connect_ex', 'fileno', 'listen', - 'getpeername', 'getsockname', - 'getsockopt', 'setsockopt', - 'recv', 'recvfrom', 'send', 'sendto', - 'setblocking', - 'shutdown'): + _s = "def %s(self, *args): return self._sock.%s(*args)\n\n" + for _m in _socketmethods: exec _s % (_m, _m) +class _closedsocket: + + def _bummer(self): + raise error(9, 'Bad file descriptor') + + _s = "def %s(self, *args): self._bummer()\n\n" + for _m in _socketmethods: + exec _s % _m + + class _fileobject: def __init__(self, sock, mode, bufsize): |