summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-10-09 15:18:55 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2016-10-09 15:18:55 (GMT)
commit75907bc5b500fa6708c06c88261e5c6fa189f20e (patch)
tree32dec6076f76686f3120e609192cc6bb0bef2fef
parent3b8c54748912fb961dc1d18954b10d45650a5a21 (diff)
parent0aa7887f431f65f1d320c467ad9065ac2697db20 (diff)
downloadcpython-75907bc5b500fa6708c06c88261e5c6fa189f20e.zip
cpython-75907bc5b500fa6708c06c88261e5c6fa189f20e.tar.gz
cpython-75907bc5b500fa6708c06c88261e5c6fa189f20e.tar.bz2
Issue #28389: Merge from 3.5
-rw-r--r--Doc/library/xmlrpc.client.rst38
1 files changed, 16 insertions, 22 deletions
diff --git a/Doc/library/xmlrpc.client.rst b/Doc/library/xmlrpc.client.rst
index 48d5a6e..390828e 100644
--- a/Doc/library/xmlrpc.client.rst
+++ b/Doc/library/xmlrpc.client.rst
@@ -568,33 +568,27 @@ Example of Client Usage
print("ERROR", v)
To access an XML-RPC server through a HTTP proxy, you need to define a custom
-transport. The following example shows how:
+transport. The following example shows how::
-.. Example taken from http://lowlife.jp/nobonobo/wiki/xmlrpcwithproxy.html
-
-::
-
- import xmlrpc.client, http.client
+ import http.client
+ import xmlrpc.client
class ProxiedTransport(xmlrpc.client.Transport):
- def set_proxy(self, proxy):
- self.proxy = proxy
- def make_connection(self, host):
- self.realhost = host
- h = http.client.HTTPConnection(self.proxy)
- return h
-
- def send_request(self, connection, handler, request_body, debug):
- connection.putrequest("POST", 'http://%s%s' % (self.realhost, handler))
+ def set_proxy(self, host, port=None, headers=None):
+ self.proxy = host, port
+ self.proxy_headers = headers
- def send_host(self, connection, host):
- connection.putheader('Host', self.realhost)
-
- p = ProxiedTransport()
- p.set_proxy('proxy-server:8080')
- server = xmlrpc.client.ServerProxy('http://time.xmlrpc.com/RPC2', transport=p)
- print(server.currentTime.getCurrentTime())
+ def make_connection(self, host):
+ connection = http.client.HTTPConnection(*self.proxy)
+ connection.set_tunnel(host, headers=self.proxy_headers)
+ self._connection = host, connection
+ return connection
+
+ transport = ProxiedTransport()
+ transport.set_proxy('proxy-server', 8080)
+ server = xmlrpc.client.ServerProxy('http://betty.userland.com', transport=transport)
+ print(server.examples.getStateName(41))
Example of Client and Server Usage