Commit dab64260 authored by Antoine Pitrou's avatar Antoine Pitrou

Remove references to read() and write() methods, which are useless synonyms of

recv() and send()
parent 792ff3e7
...@@ -31,10 +31,9 @@ the documents in the "See Also" section at the bottom. ...@@ -31,10 +31,9 @@ the documents in the "See Also" section at the bottom.
This module provides a class, :class:`ssl.SSLSocket`, which is derived from the This module provides a class, :class:`ssl.SSLSocket`, which is derived from the
:class:`socket.socket` type, and provides a socket-like wrapper that also :class:`socket.socket` type, and provides a socket-like wrapper that also
encrypts and decrypts the data going over the socket with SSL. It supports encrypts and decrypts the data going over the socket with SSL. It supports
additional :meth:`read` and :meth:`write` methods, along with a method, additional methods such as :meth:`getpeercert`, which retrieves the
:meth:`getpeercert`, to retrieve the certificate of the other side of the certificate of the other side of the connection, and :meth:`cipher`,which
connection, and a method, :meth:`cipher`, to retrieve the cipher being used for retrieves the cipher being used for the secure connection.
the secure connection.
For more sophisticated applications, the :class:`ssl.SSLContext` class For more sophisticated applications, the :class:`ssl.SSLContext` class
helps manage settings and certificates, which can then be inherited helps manage settings and certificates, which can then be inherited
...@@ -131,10 +130,11 @@ Functions, Constants, and Exceptions ...@@ -131,10 +130,11 @@ Functions, Constants, and Exceptions
blocking behavior of the socket I/O involved in the handshake. blocking behavior of the socket I/O involved in the handshake.
The parameter ``suppress_ragged_eofs`` specifies how the The parameter ``suppress_ragged_eofs`` specifies how the
:meth:`SSLSocket.read` method should signal unexpected EOF from the other end :meth:`SSLSocket.recv` method should signal unexpected EOF from the other end
of the connection. If specified as :const:`True` (the default), it returns a of the connection. If specified as :const:`True` (the default), it returns a
normal EOF in response to unexpected EOF errors raised from the underlying normal EOF (an empty bytes object) in response to unexpected EOF errors
socket; if :const:`False`, it will raise the exceptions back to the caller. raised from the underlying socket; if :const:`False`, it will raise the
exceptions back to the caller.
.. versionchanged:: 3.2 .. versionchanged:: 3.2
New optional argument *ciphers*. New optional argument *ciphers*.
...@@ -327,23 +327,10 @@ SSL Sockets ...@@ -327,23 +327,10 @@ SSL Sockets
SSL sockets provide the basic interface of :ref:`socket-objects`. However, SSL sockets provide the basic interface of :ref:`socket-objects`. However,
not all functionality is supported (for example, passing a non-zero ``flags`` not all functionality is supported (for example, passing a non-zero ``flags``
argument to :meth:`recv()` is not allowed). argument to :meth:`~socket.socket.recv()` is not allowed).
SSL sockets also have the following additional methods and attributes: SSL sockets also have the following additional methods and attributes:
.. method:: SSLSocket.read(nbytes=1024, buffer=None)
Reads up to ``nbytes`` bytes from the SSL-encrypted channel and returns them.
If the ``buffer`` is specified, it will attempt to read into the buffer the
minimum of the size of the buffer and ``nbytes``, if that is specified. If
no buffer is specified, an immutable buffer is allocated and returned with
the data read from the socket.
.. method:: SSLSocket.write(data)
Writes the ``data`` to the other side of the connection, using the SSL
channel to encrypt. Returns the number of bytes written.
.. method:: SSLSocket.do_handshake() .. method:: SSLSocket.do_handshake()
Performs the SSL setup handshake. If the socket is non-blocking, this method Performs the SSL setup handshake. If the socket is non-blocking, this method
...@@ -699,11 +686,11 @@ certificate, sends some bytes, and reads part of the response:: ...@@ -699,11 +686,11 @@ certificate, sends some bytes, and reads part of the response::
print(pprint.pformat(ssl_sock.getpeercert())) print(pprint.pformat(ssl_sock.getpeercert()))
# Set a simple HTTP request -- use http.client in actual code. # Set a simple HTTP request -- use http.client in actual code.
ssl_sock.write(b"GET / HTTP/1.0\r\nHost: www.verisign.com\r\n\r\n") ssl_sock.sendall(b"GET / HTTP/1.0\r\nHost: www.verisign.com\r\n\r\n")
# Read a chunk of data. Will not necessarily # Read a chunk of data. Will not necessarily
# read all the data returned by the server. # read all the data returned by the server.
data = ssl_sock.read() data = ssl_sock.recv()
# note that closing the SSLSocket will also close the underlying socket # note that closing the SSLSocket will also close the underlying socket
ssl_sock.close() ssl_sock.close()
...@@ -761,9 +748,8 @@ host ``linuxfr.org``:: ...@@ -761,9 +748,8 @@ host ``linuxfr.org``::
Now that you are assured of its authenticity, you can proceed to talk with Now that you are assured of its authenticity, you can proceed to talk with
the server:: the server::
>>> conn.write(b"HEAD / HTTP/1.0\r\nHost: linuxfr.org\r\n\r\n") >>> conn.sendall(b"HEAD / HTTP/1.0\r\nHost: linuxfr.org\r\n\r\n")
38 >>> pprint.pprint(conn.recv(1024).split(b"\r\n"))
>>> pprint.pprint(conn.read().split(b"\r\n"))
[b'HTTP/1.1 302 Found', [b'HTTP/1.1 302 Found',
b'Date: Sun, 16 May 2010 13:43:28 GMT', b'Date: Sun, 16 May 2010 13:43:28 GMT',
b'Server: Apache/2.2', b'Server: Apache/2.2',
...@@ -812,14 +798,14 @@ Then you'll read data from the ``connstream`` and do something with it till you ...@@ -812,14 +798,14 @@ Then you'll read data from the ``connstream`` and do something with it till you
are finished with the client (or the client is finished with you):: are finished with the client (or the client is finished with you)::
def deal_with_client(connstream): def deal_with_client(connstream):
data = connstream.read() data = connstream.recv(1024)
# empty data means the client is finished with us # empty data means the client is finished with us
while data: while data:
if not do_something(connstream, data): if not do_something(connstream, data):
# we'll assume do_something returns False # we'll assume do_something returns False
# when we're finished with client # when we're finished with client
break break
data = connstream.read() data = connstream.recv(1024)
# finished with client # finished with client
And go back to listening for new client connections (of course, a real server And go back to listening for new client connections (of course, a real server
......
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