mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
#5174: fix wrong file closing in example.
This commit is contained in:
parent
8e5e438d21
commit
34feea3205
1 changed files with 4 additions and 6 deletions
|
@ -318,9 +318,8 @@ XMLRPC::
|
||||||
import xmlrpclib
|
import xmlrpclib
|
||||||
|
|
||||||
def python_logo():
|
def python_logo():
|
||||||
handle = open("python_logo.jpg")
|
with open("python_logo.jpg") as handle:
|
||||||
return xmlrpclib.Binary(handle.read())
|
return xmlrpclib.Binary(handle.read())
|
||||||
handle.close()
|
|
||||||
|
|
||||||
server = SimpleXMLRPCServer(("localhost", 8000))
|
server = SimpleXMLRPCServer(("localhost", 8000))
|
||||||
print "Listening on port 8000..."
|
print "Listening on port 8000..."
|
||||||
|
@ -333,9 +332,8 @@ The client gets the image and saves it to a file::
|
||||||
import xmlrpclib
|
import xmlrpclib
|
||||||
|
|
||||||
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
|
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
|
||||||
handle = open("fetched_python_logo.jpg", "w")
|
with open("fetched_python_logo.jpg", "w") as handle:
|
||||||
handle.write(proxy.python_logo().data)
|
handle.write(proxy.python_logo().data)
|
||||||
handle.close()
|
|
||||||
|
|
||||||
.. _fault-objects:
|
.. _fault-objects:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue