#7801: fix xmlrpclib binary example, open the picture in binary mode
Use also the with syntax (consistent with python trunk example).
This commit is contained in:
parent
66da2f37c3
commit
757db83dce
@ -283,9 +283,8 @@ XMLRPC::
|
|||||||
import xmlrpc.client
|
import xmlrpc.client
|
||||||
|
|
||||||
def python_logo():
|
def python_logo():
|
||||||
handle = open("python_logo.jpg")
|
with open("python_logo.jpg", "rb") as handle:
|
||||||
return xmlrpc.client.Binary(handle.read())
|
return xmlrpc.client.Binary(handle.read())
|
||||||
handle.close()
|
|
||||||
|
|
||||||
server = SimpleXMLRPCServer(("localhost", 8000))
|
server = SimpleXMLRPCServer(("localhost", 8000))
|
||||||
print("Listening on port 8000...")
|
print("Listening on port 8000...")
|
||||||
@ -298,9 +297,8 @@ The client gets the image and saves it to a file::
|
|||||||
import xmlrpc.client
|
import xmlrpc.client
|
||||||
|
|
||||||
proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
|
proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
|
||||||
handle = open("fetched_python_logo.jpg", "w")
|
with open("fetched_python_logo.jpg", "wb") as handle:
|
||||||
handle.write(proxy.python_logo().data)
|
handle.write(proxy.python_logo().data)
|
||||||
handle.close()
|
|
||||||
|
|
||||||
.. _fault-objects:
|
.. _fault-objects:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user