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

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