import xmlrpclib
def python_logo():
- handle = open("python_logo.jpg")
- return xmlrpclib.Binary(handle.read())
- handle.close()
+ with open("python_logo.jpg") as handle:
+ return xmlrpclib.Binary(handle.read())
server = SimpleXMLRPCServer(("localhost", 8000))
print "Listening on port 8000..."
import xmlrpclib
proxy = xmlrpclib.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", "w") as handle:
+ handle.write(proxy.python_logo().data)
.. _fault-objects: