mirror of
https://github.com/python/cpython.git
synced 2025-10-07 15:42:02 +00:00
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
1 changed files with 18 additions and 8 deletions
|
@ -122,13 +122,18 @@ def getfqdn(name=''):
|
||||||
# These are not actually used on other platforms.
|
# 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:
|
class _socketobject:
|
||||||
|
|
||||||
def __init__(self, sock):
|
def __init__(self, sock):
|
||||||
self._sock = sock
|
self._sock = sock
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self._sock = 0
|
self._sock = _closedsocket()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.close()
|
self.close()
|
||||||
|
@ -143,16 +148,21 @@ class _socketobject:
|
||||||
def makefile(self, mode='r', bufsize=-1):
|
def makefile(self, mode='r', bufsize=-1):
|
||||||
return _fileobject(self._sock, mode, bufsize)
|
return _fileobject(self._sock, mode, bufsize)
|
||||||
|
|
||||||
_s = "def %s(self, *args): return apply(self._sock.%s, args)\n\n"
|
_s = "def %s(self, *args): return self._sock.%s(*args)\n\n"
|
||||||
for _m in ('bind', 'connect', 'connect_ex', 'fileno', 'listen',
|
for _m in _socketmethods:
|
||||||
'getpeername', 'getsockname',
|
|
||||||
'getsockopt', 'setsockopt',
|
|
||||||
'recv', 'recvfrom', 'send', 'sendto',
|
|
||||||
'setblocking',
|
|
||||||
'shutdown'):
|
|
||||||
exec _s % (_m, _m)
|
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:
|
class _fileobject:
|
||||||
|
|
||||||
def __init__(self, sock, mode, bufsize):
|
def __init__(self, sock, mode, bufsize):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue