From: Victor Stinner Date: Sat, 30 Jan 2010 02:16:55 +0000 (+0000) Subject: #7801: fix xmlrpclib binary example, open the picture in binary mode X-Git-Tag: v3.2a1~1782 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=757db83dcef95ff71c45261ddba4a9d195a1dcbe;p=python #7801: fix xmlrpclib binary example, open the picture in binary mode Use also the with syntax (consistent with python trunk example). --- diff --git a/Doc/library/xmlrpc.client.rst b/Doc/library/xmlrpc.client.rst index 52d236ee81..1bcc4234cd 100644 --- a/Doc/library/xmlrpc.client.rst +++ b/Doc/library/xmlrpc.client.rst @@ -283,9 +283,8 @@ XMLRPC:: import xmlrpc.client def python_logo(): - handle = open("python_logo.jpg") - return xmlrpc.client.Binary(handle.read()) - handle.close() + with open("python_logo.jpg", "rb") as handle: + return xmlrpc.client.Binary(handle.read()) server = SimpleXMLRPCServer(("localhost", 8000)) print("Listening on port 8000...") @@ -298,9 +297,8 @@ The client gets the image and saves it to a file:: import xmlrpc.client proxy = xmlrpc.client.ServerProxy("http://localhost:8000/") - handle = open("fetched_python_logo.jpg", "w") - handle.write(proxy.python_logo().data) - handle.close() + with open("fetched_python_logo.jpg", "wb") as handle: + handle.write(proxy.python_logo().data) .. _fault-objects: