@@ -31,10 +31,9 @@ the documents in the "See Also" section at the bottom.
3131This module provides a class, :class: `ssl.SSLSocket `, which is derived from the
3232:class: `socket.socket ` type, and provides a socket-like wrapper that also
3333encrypts and decrypts the data going over the socket with SSL. It supports
34- additional :meth: `read ` and :meth: `write ` methods, along with a method,
35- :meth: `getpeercert `, to retrieve the certificate of the other side of the
36- connection, and a method, :meth: `cipher `, to retrieve the cipher being used for
37- the secure connection.
34+ additional methods such as :meth: `getpeercert `, which retrieves the
35+ certificate of the other side of the connection, and :meth: `cipher `,which
36+ retrieves the cipher being used for the secure connection.
3837
3938For more sophisticated applications, the :class: `ssl.SSLContext ` class
4039helps manage settings and certificates, which can then be inherited
@@ -131,10 +130,11 @@ Functions, Constants, and Exceptions
131130 blocking behavior of the socket I/O involved in the handshake.
132131
133132 The parameter ``suppress_ragged_eofs `` specifies how the
134- :meth: `SSLSocket.read ` method should signal unexpected EOF from the other end
133+ :meth: `SSLSocket.recv ` method should signal unexpected EOF from the other end
135134 of the connection. If specified as :const: `True ` (the default), it returns a
136- normal EOF in response to unexpected EOF errors raised from the underlying
137- socket; if :const: `False `, it will raise the exceptions back to the caller.
135+ normal EOF (an empty bytes object) in response to unexpected EOF errors
136+ raised from the underlying socket; if :const: `False `, it will raise the
137+ exceptions back to the caller.
138138
139139 .. versionchanged :: 3.2
140140 New optional argument *ciphers *.
@@ -327,23 +327,10 @@ SSL Sockets
327327
328328SSL sockets provide the basic interface of :ref: `socket-objects `. However,
329329not all functionality is supported (for example, passing a non-zero ``flags ``
330- argument to :meth: `recv() ` is not allowed).
330+ argument to :meth: `~socket.socket. recv() ` is not allowed).
331331
332332SSL sockets also have the following additional methods and attributes:
333333
334- .. method :: SSLSocket.read(nbytes=1024, buffer=None)
335-
336- Reads up to ``nbytes `` bytes from the SSL-encrypted channel and returns them.
337- If the ``buffer `` is specified, it will attempt to read into the buffer the
338- minimum of the size of the buffer and ``nbytes ``, if that is specified. If
339- no buffer is specified, an immutable buffer is allocated and returned with
340- the data read from the socket.
341-
342- .. method :: SSLSocket.write(data)
343-
344- Writes the ``data `` to the other side of the connection, using the SSL
345- channel to encrypt. Returns the number of bytes written.
346-
347334.. method :: SSLSocket.do_handshake()
348335
349336 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::
699686 print(pprint.pformat(ssl_sock.getpeercert()))
700687
701688 # Set a simple HTTP request -- use http.client in actual code.
702- ssl_sock.write (b"GET / HTTP/1.0\r\nHost: www.verisign.com\r\n\r\n")
689+ ssl_sock.sendall (b"GET / HTTP/1.0\r\nHost: www.verisign.com\r\n\r\n")
703690
704691 # Read a chunk of data. Will not necessarily
705692 # read all the data returned by the server.
706- data = ssl_sock.read ()
693+ data = ssl_sock.recv ()
707694
708695 # note that closing the SSLSocket will also close the underlying socket
709696 ssl_sock.close()
@@ -761,9 +748,8 @@ host ``linuxfr.org``::
761748Now that you are assured of its authenticity, you can proceed to talk with
762749the server::
763750
764- >>> conn.write(b"HEAD / HTTP/1.0\r\nHost: linuxfr.org\r\n\r\n")
765- 38
766- >>> pprint.pprint(conn.read().split(b"\r\n"))
751+ >>> conn.sendall(b"HEAD / HTTP/1.0\r\nHost: linuxfr.org\r\n\r\n")
752+ >>> pprint.pprint(conn.recv(1024).split(b"\r\n"))
767753 [b'HTTP/1.1 302 Found',
768754 b'Date: Sun, 16 May 2010 13:43:28 GMT',
769755 b'Server: Apache/2.2',
@@ -812,14 +798,14 @@ Then you'll read data from the ``connstream`` and do something with it till you
812798are finished with the client (or the client is finished with you)::
813799
814800 def deal_with_client(connstream):
815- data = connstream.read( )
801+ data = connstream.recv(1024 )
816802 # empty data means the client is finished with us
817803 while data:
818804 if not do_something(connstream, data):
819805 # we'll assume do_something returns False
820806 # when we're finished with client
821807 break
822- data = connstream.read( )
808+ data = connstream.recv(1024 )
823809 # finished with client
824810
825811And go back to listening for new client connections (of course, a real server
0 commit comments