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

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