mirror of https://github.com/python/cpython
bpo-31853: Replaced socket.method calls with super() in SSLSocket. (#4048)
This commit is contained in:
parent
d0e31b980f
commit
746cc75541
39
Lib/ssl.py
39
Lib/ssl.py
|
@ -786,17 +786,16 @@ class SSLSocket(socket):
|
||||||
self.do_handshake_on_connect = do_handshake_on_connect
|
self.do_handshake_on_connect = do_handshake_on_connect
|
||||||
self.suppress_ragged_eofs = suppress_ragged_eofs
|
self.suppress_ragged_eofs = suppress_ragged_eofs
|
||||||
if sock is not None:
|
if sock is not None:
|
||||||
socket.__init__(self,
|
super().__init__(family=sock.family,
|
||||||
family=sock.family,
|
type=sock.type,
|
||||||
type=sock.type,
|
proto=sock.proto,
|
||||||
proto=sock.proto,
|
fileno=sock.fileno())
|
||||||
fileno=sock.fileno())
|
|
||||||
self.settimeout(sock.gettimeout())
|
self.settimeout(sock.gettimeout())
|
||||||
sock.detach()
|
sock.detach()
|
||||||
elif fileno is not None:
|
elif fileno is not None:
|
||||||
socket.__init__(self, fileno=fileno)
|
super().__init__(fileno=fileno)
|
||||||
else:
|
else:
|
||||||
socket.__init__(self, family=family, type=type, proto=proto)
|
super().__init__(family=family, type=type, proto=proto)
|
||||||
|
|
||||||
# See if we are connected
|
# See if we are connected
|
||||||
try:
|
try:
|
||||||
|
@ -952,7 +951,7 @@ class SSLSocket(socket):
|
||||||
self.__class__)
|
self.__class__)
|
||||||
return self._sslobj.write(data)
|
return self._sslobj.write(data)
|
||||||
else:
|
else:
|
||||||
return socket.send(self, data, flags)
|
return super().send(data, flags)
|
||||||
|
|
||||||
def sendto(self, data, flags_or_addr, addr=None):
|
def sendto(self, data, flags_or_addr, addr=None):
|
||||||
self._checkClosed()
|
self._checkClosed()
|
||||||
|
@ -960,9 +959,9 @@ class SSLSocket(socket):
|
||||||
raise ValueError("sendto not allowed on instances of %s" %
|
raise ValueError("sendto not allowed on instances of %s" %
|
||||||
self.__class__)
|
self.__class__)
|
||||||
elif addr is None:
|
elif addr is None:
|
||||||
return socket.sendto(self, data, flags_or_addr)
|
return super().sendto(data, flags_or_addr)
|
||||||
else:
|
else:
|
||||||
return socket.sendto(self, data, flags_or_addr, addr)
|
return super().sendto(data, flags_or_addr, addr)
|
||||||
|
|
||||||
def sendmsg(self, *args, **kwargs):
|
def sendmsg(self, *args, **kwargs):
|
||||||
# Ensure programs don't send data unencrypted if they try to
|
# Ensure programs don't send data unencrypted if they try to
|
||||||
|
@ -984,7 +983,7 @@ class SSLSocket(socket):
|
||||||
v = self.send(byte_view[count:])
|
v = self.send(byte_view[count:])
|
||||||
count += v
|
count += v
|
||||||
else:
|
else:
|
||||||
return socket.sendall(self, data, flags)
|
return super().sendall(data, flags)
|
||||||
|
|
||||||
def sendfile(self, file, offset=0, count=None):
|
def sendfile(self, file, offset=0, count=None):
|
||||||
"""Send a file, possibly by using os.sendfile() if this is a
|
"""Send a file, possibly by using os.sendfile() if this is a
|
||||||
|
@ -1005,7 +1004,7 @@ class SSLSocket(socket):
|
||||||
self.__class__)
|
self.__class__)
|
||||||
return self.read(buflen)
|
return self.read(buflen)
|
||||||
else:
|
else:
|
||||||
return socket.recv(self, buflen, flags)
|
return super().recv(buflen, flags)
|
||||||
|
|
||||||
def recv_into(self, buffer, nbytes=None, flags=0):
|
def recv_into(self, buffer, nbytes=None, flags=0):
|
||||||
self._checkClosed()
|
self._checkClosed()
|
||||||
|
@ -1020,7 +1019,7 @@ class SSLSocket(socket):
|
||||||
self.__class__)
|
self.__class__)
|
||||||
return self.read(nbytes, buffer)
|
return self.read(nbytes, buffer)
|
||||||
else:
|
else:
|
||||||
return socket.recv_into(self, buffer, nbytes, flags)
|
return super().recv_into(buffer, nbytes, flags)
|
||||||
|
|
||||||
def recvfrom(self, buflen=1024, flags=0):
|
def recvfrom(self, buflen=1024, flags=0):
|
||||||
self._checkClosed()
|
self._checkClosed()
|
||||||
|
@ -1028,7 +1027,7 @@ class SSLSocket(socket):
|
||||||
raise ValueError("recvfrom not allowed on instances of %s" %
|
raise ValueError("recvfrom not allowed on instances of %s" %
|
||||||
self.__class__)
|
self.__class__)
|
||||||
else:
|
else:
|
||||||
return socket.recvfrom(self, buflen, flags)
|
return super().recvfrom(buflen, flags)
|
||||||
|
|
||||||
def recvfrom_into(self, buffer, nbytes=None, flags=0):
|
def recvfrom_into(self, buffer, nbytes=None, flags=0):
|
||||||
self._checkClosed()
|
self._checkClosed()
|
||||||
|
@ -1036,7 +1035,7 @@ class SSLSocket(socket):
|
||||||
raise ValueError("recvfrom_into not allowed on instances of %s" %
|
raise ValueError("recvfrom_into not allowed on instances of %s" %
|
||||||
self.__class__)
|
self.__class__)
|
||||||
else:
|
else:
|
||||||
return socket.recvfrom_into(self, buffer, nbytes, flags)
|
return super().recvfrom_into(buffer, nbytes, flags)
|
||||||
|
|
||||||
def recvmsg(self, *args, **kwargs):
|
def recvmsg(self, *args, **kwargs):
|
||||||
raise NotImplementedError("recvmsg not allowed on instances of %s" %
|
raise NotImplementedError("recvmsg not allowed on instances of %s" %
|
||||||
|
@ -1056,7 +1055,7 @@ class SSLSocket(socket):
|
||||||
def shutdown(self, how):
|
def shutdown(self, how):
|
||||||
self._checkClosed()
|
self._checkClosed()
|
||||||
self._sslobj = None
|
self._sslobj = None
|
||||||
socket.shutdown(self, how)
|
super().shutdown(how)
|
||||||
|
|
||||||
def unwrap(self):
|
def unwrap(self):
|
||||||
if self._sslobj:
|
if self._sslobj:
|
||||||
|
@ -1068,7 +1067,7 @@ class SSLSocket(socket):
|
||||||
|
|
||||||
def _real_close(self):
|
def _real_close(self):
|
||||||
self._sslobj = None
|
self._sslobj = None
|
||||||
socket._real_close(self)
|
super()._real_close()
|
||||||
|
|
||||||
def do_handshake(self, block=False):
|
def do_handshake(self, block=False):
|
||||||
"""Perform a TLS/SSL handshake."""
|
"""Perform a TLS/SSL handshake."""
|
||||||
|
@ -1093,10 +1092,10 @@ class SSLSocket(socket):
|
||||||
session=self._session)
|
session=self._session)
|
||||||
try:
|
try:
|
||||||
if connect_ex:
|
if connect_ex:
|
||||||
rc = socket.connect_ex(self, addr)
|
rc = super().connect_ex(addr)
|
||||||
else:
|
else:
|
||||||
rc = None
|
rc = None
|
||||||
socket.connect(self, addr)
|
super().connect(addr)
|
||||||
if not rc:
|
if not rc:
|
||||||
self._connected = True
|
self._connected = True
|
||||||
if self.do_handshake_on_connect:
|
if self.do_handshake_on_connect:
|
||||||
|
@ -1121,7 +1120,7 @@ class SSLSocket(socket):
|
||||||
a tuple containing that new connection wrapped with a server-side
|
a tuple containing that new connection wrapped with a server-side
|
||||||
SSL channel, and the address of the remote client."""
|
SSL channel, and the address of the remote client."""
|
||||||
|
|
||||||
newsock, addr = socket.accept(self)
|
newsock, addr = super().accept()
|
||||||
newsock = self.context.wrap_socket(newsock,
|
newsock = self.context.wrap_socket(newsock,
|
||||||
do_handshake_on_connect=self.do_handshake_on_connect,
|
do_handshake_on_connect=self.do_handshake_on_connect,
|
||||||
suppress_ragged_eofs=self.suppress_ragged_eofs,
|
suppress_ragged_eofs=self.suppress_ragged_eofs,
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Use super().method instead of socket.method in SSLSocket. They were
|
||||||
|
there most likely for legacy reasons.
|
Loading…
Reference in New Issue