Blame SOURCES/00281-add-context-parameter-to-xmlrpclib.ServerProxy.patch

25c6e4
25c6e4
# HG changeset patch
25c6e4
# User Benjamin Peterson <benjamin@python.org>
25c6e4
# Date 1417319735 18000
25c6e4
# Node ID 62bd574e95d5ec4b37ca8f72ae6523ea7d6c11cd
25c6e4
# Parent  1ac5aec658f6972c3372f139ce69ee6799dc0b2e
25c6e4
add context parameter to xmlrpclib.ServerProxy (#22960)
25c6e4
25c6e4
Patch from Alex Gaynor.
25c6e4
25c6e4
diff --git a/Doc/library/xmlrpclib.rst b/Doc/library/xmlrpclib.rst
25c6e4
--- a/Doc/library/xmlrpclib.rst
25c6e4
+++ b/Doc/library/xmlrpclib.rst
25c6e4
@@ -39,7 +39,7 @@ between conformable Python objects and X
25c6e4
    For https URIs, :mod:`xmlrpclib` now performs all the necessary certificate
25c6e4
    and hostname checks by default
25c6e4
 
25c6e4
-.. class:: ServerProxy(uri[, transport[, encoding[, verbose[,  allow_none[, use_datetime]]]]])
25c6e4
+.. class:: ServerProxy(uri[, transport[, encoding[, verbose[, allow_none[, use_datetime[, context]]]]]])
25c6e4
 
25c6e4
    A :class:`ServerProxy` instance is an object that manages communication with a
25c6e4
    remote XML-RPC server.  The required first argument is a URI (Uniform Resource
25c6e4
@@ -57,11 +57,13 @@ between conformable Python objects and X
25c6e4
    :class:`datetime.datetime` objects may be passed to calls.
25c6e4
 
25c6e4
    Both the HTTP and HTTPS transports support the URL syntax extension for HTTP
25c6e4
-   Basic Authentication: ``http://user:pass@host:port/path``.  The  ``user:pass``
25c6e4
+   Basic Authentication: ``http://user:pass@host:port/path``.  The ``user:pass``
25c6e4
    portion will be base64-encoded as an HTTP 'Authorization' header, and sent to
25c6e4
    the remote server as part of the connection process when invoking an XML-RPC
25c6e4
    method.  You only need to use this if the remote server requires a Basic
25c6e4
-   Authentication user and password.
25c6e4
+   Authentication user and password. If an HTTPS url is provided, *context* may
25c6e4
+   be :class:`ssl.SSLContext` and configures the SSL settings of the underlying
25c6e4
+   HTTPS connection.
25c6e4
 
25c6e4
    The returned instance is a proxy object with methods that can be used to invoke
25c6e4
    corresponding RPC calls on the remote server.  If the remote server supports the
25c6e4
@@ -131,6 +133,9 @@ between conformable Python objects and X
25c6e4
       *__dict__* attribute and don't have a base class that is marshalled in a
25c6e4
       special way.
25c6e4
 
25c6e4
+   .. versionchanged:: 2.7.9
25c6e4
+      Added the *context* argument.
25c6e4
+
25c6e4
 
25c6e4
 .. seealso::
25c6e4
 
25c6e4
diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py
25c6e4
--- a/Lib/xmlrpclib.py
25c6e4
+++ b/Lib/xmlrpclib.py
25c6e4
@@ -1478,6 +1478,10 @@ class Transport:
25c6e4
 class SafeTransport(Transport):
25c6e4
     """Handles an HTTPS transaction to an XML-RPC server."""
25c6e4
 
25c6e4
+    def __init__(self, use_datetime=0, context=None):
25c6e4
+        Transport.__init__(self, use_datetime=use_datetime)
25c6e4
+        self.context = context
25c6e4
+
25c6e4
     # FIXME: mostly untested
25c6e4
 
25c6e4
     def make_connection(self, host):
25c6e4
@@ -1493,7 +1497,7 @@ class SafeTransport(Transport):
25c6e4
                 )
25c6e4
         else:
25c6e4
             chost, self._extra_headers, x509 = self.get_host_info(host)
25c6e4
-            self._connection = host, HTTPS(chost, None, **(x509 or {}))
25c6e4
+            self._connection = host, HTTPS(chost, None, context=self.context, **(x509 or {}))
25c6e4
             return self._connection[1]
25c6e4
 
25c6e4
 ##
25c6e4
@@ -1536,7 +1540,7 @@ class ServerProxy:
25c6e4
     """
25c6e4
 
25c6e4
     def __init__(self, uri, transport=None, encoding=None, verbose=0,
25c6e4
-                 allow_none=0, use_datetime=0):
25c6e4
+                 allow_none=0, use_datetime=0, context=None):
25c6e4
         # establish a "logical" server connection
25c6e4
 
25c6e4
         if isinstance(uri, unicode):
25c6e4
@@ -1553,7 +1557,7 @@ class ServerProxy:
25c6e4
 
25c6e4
         if transport is None:
25c6e4
             if type == "https":
25c6e4
-                transport = SafeTransport(use_datetime=use_datetime)
25c6e4
+                transport = SafeTransport(use_datetime=use_datetime, context=context)
25c6e4
             else:
25c6e4
                 transport = Transport(use_datetime=use_datetime)
25c6e4
         self.__transport = transport
25c6e4
 
25c6e4