diff options
author | Brett Cannon <brett@python.org> | 2014-03-21 15:24:40 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2014-03-21 15:24:40 (GMT) |
commit | 33a40003745302eff5e6031d24d26642763fb6d8 (patch) | |
tree | 75787adf85b136178f9053a54a2ed46f3f98c247 /Doc | |
parent | 051f37d2e739981eac45051f6f2b873d2ef4699f (diff) | |
download | cpython-33a40003745302eff5e6031d24d26642763fb6d8.zip cpython-33a40003745302eff5e6031d24d26642763fb6d8.tar.gz cpython-33a40003745302eff5e6031d24d26642763fb6d8.tar.bz2 |
Issue #20627: xmlrpc.client.ServerProxy is now a context manager.
Patch by Claudiu Popa.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/xmlrpc.client.rst | 23 | ||||
-rw-r--r-- | Doc/whatsnew/3.5.rst | 3 |
2 files changed, 16 insertions, 10 deletions
diff --git a/Doc/library/xmlrpc.client.rst b/Doc/library/xmlrpc.client.rst index 3cb19d1..6f14227 100644 --- a/Doc/library/xmlrpc.client.rst +++ b/Doc/library/xmlrpc.client.rst @@ -191,6 +191,11 @@ grouped under the reserved :attr:`system` attribute: no such string is available, an empty string is returned. The documentation string may contain HTML markup. +.. versionchanged:: 3.5 + + Instances of :class:`ServerProxy` support the :term:`context manager` protocol + for closing the underlying transport. + A working example follows. The server code:: @@ -208,9 +213,9 @@ The client code for the preceding server:: import xmlrpc.client - proxy = xmlrpc.client.ServerProxy("http://localhost:8000/") - print("3 is even: %s" % str(proxy.is_even(3))) - print("100 is even: %s" % str(proxy.is_even(100))) + with xmlrpc.client.ServerProxy("http://localhost:8000/") as proxy: + print("3 is even: %s" % str(proxy.is_even(3))) + print("100 is even: %s" % str(proxy.is_even(100))) .. _datetime-objects: @@ -518,14 +523,14 @@ Example of Client Usage from xmlrpc.client import ServerProxy, Error # server = ServerProxy("http://localhost:8000") # local server - server = ServerProxy("http://betty.userland.com") + with ServerProxy("http://betty.userland.com") as proxy: - print(server) + print(proxy) - try: - print(server.examples.getStateName(41)) - except Error as v: - print("ERROR", v) + try: + print(proxy.examples.getStateName(41)) + except Error as v: + print("ERROR", v) To access an XML-RPC server through a proxy, you need to define a custom transport. The following example shows how: diff --git a/Doc/whatsnew/3.5.rst b/Doc/whatsnew/3.5.rst index f11291b..b18bcd2 100644 --- a/Doc/whatsnew/3.5.rst +++ b/Doc/whatsnew/3.5.rst @@ -134,7 +134,8 @@ New Modules Improved Modules ================ -* None yet. +* :class:`xmlrpc.client.ServerProxy` is now a :term:`context manager` + (contributed by Claudiu Popa in :issue:`20627`). Optimizations |