Skip to content

Commit ced80d8

Browse files
miss-islingtontiran
authored andcommitted
Simplify SSLSocket / SSLObject doc string (GH-9972) (GH-13384)
Instead of maintaining the same docstring two times, let's copy common docstrings from SSLObject methods and properties to SSLSocket. (cherry picked from commit 80ed353) Co-authored-by: Christian Heimes <christian@python.org>
1 parent a22c42f commit ced80d8

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

Lib/ssl.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,12 @@ def verify_client_post_handshake(self):
781781
return self._sslobj.verify_client_post_handshake()
782782

783783

784+
def _sslcopydoc(func):
785+
"""Copy docstring from SSLObject to SSLSocket"""
786+
func.__doc__ = getattr(SSLObject, func.__name__).__doc__
787+
return func
788+
789+
784790
class SSLSocket(socket):
785791
"""This class implements a subtype of socket.socket that wraps
786792
the underlying OS socket in an SSL context when necessary, and
@@ -857,6 +863,7 @@ def _create(cls, sock, server_side=False, do_handshake_on_connect=True,
857863
return self
858864

859865
@property
866+
@_sslcopydoc
860867
def context(self):
861868
return self._context
862869

@@ -866,8 +873,8 @@ def context(self, ctx):
866873
self._sslobj.context = ctx
867874

868875
@property
876+
@_sslcopydoc
869877
def session(self):
870-
"""The SSLSession for client socket."""
871878
if self._sslobj is not None:
872879
return self._sslobj.session
873880

@@ -878,8 +885,8 @@ def session(self, session):
878885
self._sslobj.session = session
879886

880887
@property
888+
@_sslcopydoc
881889
def session_reused(self):
882-
"""Was the client session reused during handshake"""
883890
if self._sslobj is not None:
884891
return self._sslobj.session_reused
885892

@@ -929,44 +936,45 @@ def write(self, data):
929936
raise ValueError("Write on closed or unwrapped SSL socket.")
930937
return self._sslobj.write(data)
931938

939+
@_sslcopydoc
932940
def getpeercert(self, binary_form=False):
933-
"""Returns a formatted version of the data in the
934-
certificate provided by the other end of the SSL channel.
935-
Return None if no certificate was provided, {} if a
936-
certificate was provided, but not validated."""
937-
938941
self._checkClosed()
939942
self._check_connected()
940943
return self._sslobj.getpeercert(binary_form)
941944

945+
@_sslcopydoc
942946
def selected_npn_protocol(self):
943947
self._checkClosed()
944948
if self._sslobj is None or not _ssl.HAS_NPN:
945949
return None
946950
else:
947951
return self._sslobj.selected_npn_protocol()
948952

953+
@_sslcopydoc
949954
def selected_alpn_protocol(self):
950955
self._checkClosed()
951956
if self._sslobj is None or not _ssl.HAS_ALPN:
952957
return None
953958
else:
954959
return self._sslobj.selected_alpn_protocol()
955960

961+
@_sslcopydoc
956962
def cipher(self):
957963
self._checkClosed()
958964
if self._sslobj is None:
959965
return None
960966
else:
961967
return self._sslobj.cipher()
962968

969+
@_sslcopydoc
963970
def shared_ciphers(self):
964971
self._checkClosed()
965972
if self._sslobj is None:
966973
return None
967974
else:
968975
return self._sslobj.shared_ciphers()
969976

977+
@_sslcopydoc
970978
def compression(self):
971979
self._checkClosed()
972980
if self._sslobj is None:
@@ -1077,6 +1085,7 @@ def recvmsg_into(self, *args, **kwargs):
10771085
raise NotImplementedError("recvmsg_into not allowed on instances of "
10781086
"%s" % self.__class__)
10791087

1088+
@_sslcopydoc
10801089
def pending(self):
10811090
self._checkClosed()
10821091
if self._sslobj is not None:
@@ -1089,6 +1098,7 @@ def shutdown(self, how):
10891098
self._sslobj = None
10901099
super().shutdown(how)
10911100

1101+
@_sslcopydoc
10921102
def unwrap(self):
10931103
if self._sslobj:
10941104
s = self._sslobj.shutdown()
@@ -1097,6 +1107,7 @@ def unwrap(self):
10971107
else:
10981108
raise ValueError("No SSL wrapper around " + str(self))
10991109

1110+
@_sslcopydoc
11001111
def verify_client_post_handshake(self):
11011112
if self._sslobj:
11021113
return self._sslobj.verify_client_post_handshake()
@@ -1107,8 +1118,8 @@ def _real_close(self):
11071118
self._sslobj = None
11081119
super()._real_close()
11091120

1121+
@_sslcopydoc
11101122
def do_handshake(self, block=False):
1111-
"""Perform a TLS/SSL handshake."""
11121123
self._check_connected()
11131124
timeout = self.gettimeout()
11141125
try:
@@ -1166,11 +1177,8 @@ def accept(self):
11661177
server_side=True)
11671178
return newsock, addr
11681179

1180+
@_sslcopydoc
11691181
def get_channel_binding(self, cb_type="tls-unique"):
1170-
"""Get channel binding data for current connection. Raise ValueError
1171-
if the requested `cb_type` is not supported. Return bytes of the data
1172-
or None if the data is not available (e.g. before the handshake).
1173-
"""
11741182
if self._sslobj is not None:
11751183
return self._sslobj.get_channel_binding(cb_type)
11761184
else:
@@ -1180,11 +1188,8 @@ def get_channel_binding(self, cb_type="tls-unique"):
11801188
)
11811189
return None
11821190

1191+
@_sslcopydoc
11831192
def version(self):
1184-
"""
1185-
Return a string identifying the protocol version used by the
1186-
current SSL channel, or None if there is no established channel.
1187-
"""
11881193
if self._sslobj is not None:
11891194
return self._sslobj.version()
11901195
else:

0 commit comments

Comments
 (0)