[Python-checkins] cpython (merge 3.6 -> default): Issue #28389: Merge from 3.6

berker.peksag python-checkins at python.org
Sun Oct 9 11:19:14 EDT 2016


https://hg.python.org/cpython/rev/5f9351bc317e
changeset:   104413:5f9351bc317e
parent:      104410:1be8cd7cee92
parent:      104412:60c5c77c0190
user:        Berker Peksag <berker.peksag at gmail.com>
date:        Sun Oct 09 18:19:12 2016 +0300
summary:
  Issue #28389: Merge from 3.6

files:
  Doc/library/xmlrpc.client.rst |  36 +++++++++-------------
  1 files changed, 15 insertions(+), 21 deletions(-)


diff --git a/Doc/library/xmlrpc.client.rst b/Doc/library/xmlrpc.client.rst
--- a/Doc/library/xmlrpc.client.rst
+++ b/Doc/library/xmlrpc.client.rst
@@ -568,33 +568,27 @@
            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 set_proxy(self, host, port=None, headers=None):
+           self.proxy = host, port
+           self.proxy_headers = headers
 
        def make_connection(self, host):
-           self.realhost = host
-           h = http.client.HTTPConnection(self.proxy)
-           return h
+           connection = http.client.HTTPConnection(*self.proxy)
+           connection.set_tunnel(host, headers=self.proxy_headers)
+           self._connection = host, connection
+           return connection
 
-       def send_request(self, connection, handler, request_body, debug):
-           connection.putrequest("POST", 'http://%s%s' % (self.realhost, handler))
-
-       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())
+   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

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list