Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 41f92c2

Browse files
committed
Issue #22564: ssl doc: document read(), write(), pending, server_side and
server_hostname methods and attributes of SSLSocket.
1 parent 851a6cc commit 41f92c2

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

Doc/library/ssl.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,41 @@ the specification of normal, OS-level sockets. See especially the
782782

783783
SSL sockets also have the following additional methods and attributes:
784784

785+
.. method:: SSLSocket.read(len=0, buffer=None)
786+
787+
Read up to *len* bytes of data from the SSL socket and return the result as
788+
a ``bytes`` instance. If *buffer* is specified, then read into the buffer
789+
instead, and return the number of bytes read.
790+
791+
Raise :exc:`SSLWantReadError` or :exc:`SSLWantWriteError` if the socket is
792+
non-blocking and the read would block.
793+
794+
As at any time a re-negotiation is possible, a call to :meth:`read` can also
795+
cause write operations.
796+
797+
.. method:: SSLSocket.write(buf)
798+
799+
Write *buf* to the SSL socket and return the number of bytes written. The
800+
*buf* argument must be an object supporting the buffer interface.
801+
802+
Raise :exc:`SSLWantReadError` or :exc:`SSLWantWriteError` if the socket is
803+
non-blocking and the write would block.
804+
805+
As at any time a re-negotiation is possible, a call to :meth:`write` can
806+
also cause read operations.
807+
808+
.. note::
809+
810+
The :meth:`~SSLSocket.read` and :meth:`~SSLSocket.write` methods are the
811+
low-level methods that read and write unencrypted, application-level data
812+
and and decrypt/encrypt it to encrypted, wire-level data. These methods
813+
require an active SSL connection, i.e. the handshake was completed and
814+
:meth:`SSLSocket.unwrap` was not called.
815+
816+
Normally you should use the socket API methods like
817+
:meth:`~socket.socket.recv` and :meth:`~socket.socket.send` instead of these
818+
methods.
819+
785820
.. method:: SSLSocket.do_handshake()
786821

787822
Perform the SSL setup handshake.
@@ -904,6 +939,11 @@ SSL sockets also have the following additional methods and attributes:
904939
returned socket should always be used for further communication with the
905940
other side of the connection, rather than the original socket.
906941

942+
.. method:: SSLSocket.pending()
943+
944+
Returns the number of already decrypted bytes available for read, pending on
945+
the connection.
946+
907947
.. attribute:: SSLSocket.context
908948

909949
The :class:`SSLContext` object this SSL socket is tied to. If the SSL
@@ -913,6 +953,20 @@ SSL sockets also have the following additional methods and attributes:
913953

914954
.. versionadded:: 3.2
915955

956+
.. attribute:: SSLSocket.server_side
957+
958+
A boolean which is ``True`` for server-side sockets and ``False`` for
959+
client-side sockets.
960+
961+
.. versionadded:: 3.2
962+
963+
.. attribute:: SSLSocket.server_hostname
964+
965+
Hostname of the server: :class:`str` type, or ``None`` for server-side
966+
socket or if the hostname was not specified in the constructor.
967+
968+
.. versionadded:: 3.2
969+
916970

917971
SSL Contexts
918972
------------

0 commit comments

Comments
 (0)