[Python-checkins] cpython (3.2): Fix Issue #6005: Examples in the socket library documentation use sendall,

senthil.kumaran python-checkins at python.org
Thu Feb 9 10:56:30 CET 2012


http://hg.python.org/cpython/rev/2aae44aa041a
changeset:   74845:2aae44aa041a
branch:      3.2
parent:      74830:29b83d3d40d0
user:        Senthil Kumaran <senthil at uthcode.com>
date:        Thu Feb 09 17:54:17 2012 +0800
summary:
  Fix Issue #6005: Examples in the socket library documentation use sendall,
where relevant, instead send method.

files:
  Doc/howto/sockets.rst        |   2 ++
  Doc/library/socket.rst       |  13 +++++++------
  Doc/library/socketserver.rst |  10 +++++-----
  Misc/NEWS                    |   3 +++
  4 files changed, 17 insertions(+), 11 deletions(-)


diff --git a/Doc/howto/sockets.rst b/Doc/howto/sockets.rst
--- a/Doc/howto/sockets.rst
+++ b/Doc/howto/sockets.rst
@@ -1,3 +1,5 @@
+.. _socket-howto:
+
 ****************************
   Socket Programming HOWTO
 ****************************
diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst
--- a/Doc/library/socket.rst
+++ b/Doc/library/socket.rst
@@ -731,7 +731,8 @@
    optional *flags* argument has the same meaning as for :meth:`recv` above.
    Returns the number of bytes sent. Applications are responsible for checking that
    all data has been sent; if only some of the data was transmitted, the
-   application needs to attempt delivery of the remaining data.
+   application needs to attempt delivery of the remaining data. For further
+   information on this topic, consult the :ref:`socket-howto`.
 
 
 .. method:: socket.sendall(bytes[, flags])
@@ -886,8 +887,8 @@
 :meth:`~socket.bind`, :meth:`~socket.listen`, :meth:`~socket.accept` (possibly
 repeating the :meth:`~socket.accept` to service more than one client), while a
 client only needs the sequence :func:`socket`, :meth:`~socket.connect`.  Also
-note that the server does not :meth:`~socket.send`/:meth:`~socket.recv` on the
-socket it is listening on but on the new socket returned by
+note that the server does not :meth:`~socket.sendall`/:meth:`~socket.recv` on
+the socket it is listening on but on the new socket returned by
 :meth:`~socket.accept`.
 
 The first two examples support IPv4 only. ::
@@ -905,7 +906,7 @@
    while True:
        data = conn.recv(1024)
        if not data: break
-       conn.send(data)
+       conn.sendall(data)
    conn.close()
 
 ::
@@ -917,7 +918,7 @@
    PORT = 50007              # The same port as used by the server
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))
-   s.send(b'Hello, world')
+   s.sendall(b'Hello, world')
    data = s.recv(1024)
    s.close()
    print('Received', repr(data))
@@ -989,7 +990,7 @@
    if s is None:
        print('could not open socket')
        sys.exit(1)
-   s.send(b'Hello, world')
+   s.sendall(b'Hello, world')
    data = s.recv(1024)
    s.close()
    print('Received', repr(data))
diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst
--- a/Doc/library/socketserver.rst
+++ b/Doc/library/socketserver.rst
@@ -353,7 +353,7 @@
            print("{} wrote:".format(self.client_address[0]))
            print(self.data)
            # just send back the same data, but upper-cased
-           self.request.send(self.data.upper())
+           self.request.sendall(self.data.upper())
 
    if __name__ == "__main__":
        HOST, PORT = "localhost", 9999
@@ -383,7 +383,7 @@
 The difference is that the ``readline()`` call in the second handler will call
 ``recv()`` multiple times until it encounters a newline character, while the
 single ``recv()`` call in the first handler will just return what has been sent
-from the client in one ``send()`` call.
+from the client in one ``sendall()`` call.
 
 
 This is the client side::
@@ -400,7 +400,7 @@
    try:
        # Connect to server and send data
        sock.connect((HOST, PORT))
-       sock.send(bytes(data + "\n", "utf-8"))
+       sock.sendall(bytes(data + "\n", "utf-8"))
 
        # Receive data from the server and shut down
        received = str(sock.recv(1024), "utf-8")
@@ -498,7 +498,7 @@
            data = str(self.request.recv(1024), 'ascii')
            cur_thread = threading.current_thread()
            response = bytes("{}: {}".format(cur_thread.name, data), 'ascii')
-           self.request.send(response)
+           self.request.sendall(response)
 
    class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
        pass
@@ -507,7 +507,7 @@
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect((ip, port))
        try:
-           sock.send(bytes(message, 'ascii'))
+           sock.sendall(bytes(message, 'ascii'))
            response = str(sock.recv(1024), 'ascii')
            print("Received: {}".format(response))
        finally:
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -113,6 +113,9 @@
 Library
 -------
 
+- Issue #6005: Examples in the socket library documentation use sendall, where
+  relevant, instead send method.
+
 - Issue #10811: Fix recursive usage of cursors. Instead of crashing,
   raise a ProgrammingError now.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list