mirror of https://github.com/python/cpython
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.
This commit is contained in:
parent
241d69c11b
commit
e5e50591a4
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue