Commit 80ed3533 authored by Christian Heimes's avatar Christian Heimes Committed by Stéphane Wirtel

Simplify SSLSocket / SSLObject doc string (GH-9972)

Instead of maintaining the same doc string two times, let's copy common
doc strings from SSLObject methods and properties to SSLSocket.
Signed-off-by: default avatarChristian Heimes <christian@python.org>
parent f98c3c59
...@@ -781,6 +781,12 @@ class SSLObject: ...@@ -781,6 +781,12 @@ class SSLObject:
return self._sslobj.verify_client_post_handshake() return self._sslobj.verify_client_post_handshake()
def _sslcopydoc(func):
"""Copy docstring from SSLObject to SSLSocket"""
func.__doc__ = getattr(SSLObject, func.__name__).__doc__
return func
class SSLSocket(socket): class SSLSocket(socket):
"""This class implements a subtype of socket.socket that wraps """This class implements a subtype of socket.socket that wraps
the underlying OS socket in an SSL context when necessary, and the underlying OS socket in an SSL context when necessary, and
...@@ -857,6 +863,7 @@ class SSLSocket(socket): ...@@ -857,6 +863,7 @@ class SSLSocket(socket):
return self return self
@property @property
@_sslcopydoc
def context(self): def context(self):
return self._context return self._context
...@@ -866,8 +873,8 @@ class SSLSocket(socket): ...@@ -866,8 +873,8 @@ class SSLSocket(socket):
self._sslobj.context = ctx self._sslobj.context = ctx
@property @property
@_sslcopydoc
def session(self): def session(self):
"""The SSLSession for client socket."""
if self._sslobj is not None: if self._sslobj is not None:
return self._sslobj.session return self._sslobj.session
...@@ -878,8 +885,8 @@ class SSLSocket(socket): ...@@ -878,8 +885,8 @@ class SSLSocket(socket):
self._sslobj.session = session self._sslobj.session = session
@property @property
@_sslcopydoc
def session_reused(self): def session_reused(self):
"""Was the client session reused during handshake"""
if self._sslobj is not None: if self._sslobj is not None:
return self._sslobj.session_reused return self._sslobj.session_reused
...@@ -929,16 +936,13 @@ class SSLSocket(socket): ...@@ -929,16 +936,13 @@ class SSLSocket(socket):
raise ValueError("Write on closed or unwrapped SSL socket.") raise ValueError("Write on closed or unwrapped SSL socket.")
return self._sslobj.write(data) return self._sslobj.write(data)
@_sslcopydoc
def getpeercert(self, binary_form=False): def getpeercert(self, binary_form=False):
"""Returns a formatted version of the data in the
certificate provided by the other end of the SSL channel.
Return None if no certificate was provided, {} if a
certificate was provided, but not validated."""
self._checkClosed() self._checkClosed()
self._check_connected() self._check_connected()
return self._sslobj.getpeercert(binary_form) return self._sslobj.getpeercert(binary_form)
@_sslcopydoc
def selected_npn_protocol(self): def selected_npn_protocol(self):
self._checkClosed() self._checkClosed()
if self._sslobj is None or not _ssl.HAS_NPN: if self._sslobj is None or not _ssl.HAS_NPN:
...@@ -946,6 +950,7 @@ class SSLSocket(socket): ...@@ -946,6 +950,7 @@ class SSLSocket(socket):
else: else:
return self._sslobj.selected_npn_protocol() return self._sslobj.selected_npn_protocol()
@_sslcopydoc
def selected_alpn_protocol(self): def selected_alpn_protocol(self):
self._checkClosed() self._checkClosed()
if self._sslobj is None or not _ssl.HAS_ALPN: if self._sslobj is None or not _ssl.HAS_ALPN:
...@@ -953,6 +958,7 @@ class SSLSocket(socket): ...@@ -953,6 +958,7 @@ class SSLSocket(socket):
else: else:
return self._sslobj.selected_alpn_protocol() return self._sslobj.selected_alpn_protocol()
@_sslcopydoc
def cipher(self): def cipher(self):
self._checkClosed() self._checkClosed()
if self._sslobj is None: if self._sslobj is None:
...@@ -960,6 +966,7 @@ class SSLSocket(socket): ...@@ -960,6 +966,7 @@ class SSLSocket(socket):
else: else:
return self._sslobj.cipher() return self._sslobj.cipher()
@_sslcopydoc
def shared_ciphers(self): def shared_ciphers(self):
self._checkClosed() self._checkClosed()
if self._sslobj is None: if self._sslobj is None:
...@@ -967,6 +974,7 @@ class SSLSocket(socket): ...@@ -967,6 +974,7 @@ class SSLSocket(socket):
else: else:
return self._sslobj.shared_ciphers() return self._sslobj.shared_ciphers()
@_sslcopydoc
def compression(self): def compression(self):
self._checkClosed() self._checkClosed()
if self._sslobj is None: if self._sslobj is None:
...@@ -1077,6 +1085,7 @@ class SSLSocket(socket): ...@@ -1077,6 +1085,7 @@ class SSLSocket(socket):
raise NotImplementedError("recvmsg_into not allowed on instances of " raise NotImplementedError("recvmsg_into not allowed on instances of "
"%s" % self.__class__) "%s" % self.__class__)
@_sslcopydoc
def pending(self): def pending(self):
self._checkClosed() self._checkClosed()
if self._sslobj is not None: if self._sslobj is not None:
...@@ -1089,6 +1098,7 @@ class SSLSocket(socket): ...@@ -1089,6 +1098,7 @@ class SSLSocket(socket):
self._sslobj = None self._sslobj = None
super().shutdown(how) super().shutdown(how)
@_sslcopydoc
def unwrap(self): def unwrap(self):
if self._sslobj: if self._sslobj:
s = self._sslobj.shutdown() s = self._sslobj.shutdown()
...@@ -1097,6 +1107,7 @@ class SSLSocket(socket): ...@@ -1097,6 +1107,7 @@ class SSLSocket(socket):
else: else:
raise ValueError("No SSL wrapper around " + str(self)) raise ValueError("No SSL wrapper around " + str(self))
@_sslcopydoc
def verify_client_post_handshake(self): def verify_client_post_handshake(self):
if self._sslobj: if self._sslobj:
return self._sslobj.verify_client_post_handshake() return self._sslobj.verify_client_post_handshake()
...@@ -1107,8 +1118,8 @@ class SSLSocket(socket): ...@@ -1107,8 +1118,8 @@ class SSLSocket(socket):
self._sslobj = None self._sslobj = None
super()._real_close() super()._real_close()
@_sslcopydoc
def do_handshake(self, block=False): def do_handshake(self, block=False):
"""Perform a TLS/SSL handshake."""
self._check_connected() self._check_connected()
timeout = self.gettimeout() timeout = self.gettimeout()
try: try:
...@@ -1166,11 +1177,8 @@ class SSLSocket(socket): ...@@ -1166,11 +1177,8 @@ class SSLSocket(socket):
server_side=True) server_side=True)
return newsock, addr return newsock, addr
@_sslcopydoc
def get_channel_binding(self, cb_type="tls-unique"): def get_channel_binding(self, cb_type="tls-unique"):
"""Get channel binding data for current connection. Raise ValueError
if the requested `cb_type` is not supported. Return bytes of the data
or None if the data is not available (e.g. before the handshake).
"""
if self._sslobj is not None: if self._sslobj is not None:
return self._sslobj.get_channel_binding(cb_type) return self._sslobj.get_channel_binding(cb_type)
else: else:
...@@ -1180,11 +1188,8 @@ class SSLSocket(socket): ...@@ -1180,11 +1188,8 @@ class SSLSocket(socket):
) )
return None return None
@_sslcopydoc
def version(self): def version(self):
"""
Return a string identifying the protocol version used by the
current SSL channel, or None if there is no established channel.
"""
if self._sslobj is not None: if self._sslobj is not None:
return self._sslobj.version() return self._sslobj.version()
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment