]> granicus.if.org Git - python/commitdiff
add context parameter to xmlrpclib.ServerProxy (#22960)
authorBenjamin Peterson <benjamin@python.org>
Sun, 30 Nov 2014 04:32:57 +0000 (23:32 -0500)
committerBenjamin Peterson <benjamin@python.org>
Sun, 30 Nov 2014 04:32:57 +0000 (23:32 -0500)
Patch by Alex Gaynor.

Doc/library/xmlrpc.client.rst
Lib/xmlrpc/client.py
Misc/NEWS

index c06345e0a5230ab026500ee972c1c24fd8789a45..87ac86a07afa10e6a1505acb516c249c496a51aa 100644 (file)
@@ -34,7 +34,7 @@ between conformable Python objects and XML on the wire.
 
 .. class:: ServerProxy(uri, transport=None, encoding=None, verbose=False, \
                        allow_none=False, use_datetime=False, \
-                       use_builtin_types=False)
+                       use_builtin_types=False, context=None)
 
    .. versionchanged:: 3.3
       The *use_builtin_types* flag was added.
@@ -63,7 +63,9 @@ between conformable Python objects and XML on the wire.
    portion will be base64-encoded as an HTTP 'Authorization' header, and sent to
    the remote server as part of the connection process when invoking an XML-RPC
    method.  You only need to use this if the remote server requires a Basic
-   Authentication user and password.
+   Authentication user and password. If an HTTPS url is provided, *context* may
+   be :class:`ssl.SSLContext` and configures the SSL settings of the underlying
+   HTTPS connection.
 
    The returned instance is a proxy object with methods that can be used to invoke
    corresponding RPC calls on the remote server.  If the remote server supports the
@@ -127,6 +129,9 @@ between conformable Python objects and XML on the wire.
    :class:`Server` is retained as an alias for :class:`ServerProxy` for backwards
    compatibility.  New code should use :class:`ServerProxy`.
 
+   .. versionchanged:: 3.4.3
+      Added the *context* argument.
+
 
 .. seealso::
 
index c2ae7070f9ac03985d6ceb50a36adb8651a481ed..50cedfc4bb191109fe273c286e8d751d02faa177 100644 (file)
@@ -1323,6 +1323,11 @@ class Transport:
 class SafeTransport(Transport):
     """Handles an HTTPS transaction to an XML-RPC server."""
 
+    def __init__(self, use_datetime=False, use_builtin_types=False, *,
+                 context=None):
+        super().__init__(use_datetime=use_datetime, use_builtin_types=use_builtin_types)
+        self.context = context
+
     # FIXME: mostly untested
 
     def make_connection(self, host):
@@ -1336,7 +1341,7 @@ class SafeTransport(Transport):
         # host may be a string, or a (host, x509-dict) tuple
         chost, self._extra_headers, x509 = self.get_host_info(host)
         self._connection = host, http.client.HTTPSConnection(chost,
-            None, **(x509 or {}))
+            None, context=self.context, **(x509 or {}))
         return self._connection[1]
 
 ##
@@ -1379,7 +1384,8 @@ class ServerProxy:
     """
 
     def __init__(self, uri, transport=None, encoding=None, verbose=False,
-                 allow_none=False, use_datetime=False, use_builtin_types=False):
+                 allow_none=False, use_datetime=False, use_builtin_types=False,
+                 *, context=None):
         # establish a "logical" server connection
 
         # get the url
@@ -1393,10 +1399,13 @@ class ServerProxy:
         if transport is None:
             if type == "https":
                 handler = SafeTransport
+                extra_kwargs = {"context": context}
             else:
                 handler = Transport
+                extra_kwargs = {}
             transport = handler(use_datetime=use_datetime,
-                                use_builtin_types=use_builtin_types)
+                                use_builtin_types=use_builtin_types,
+                                **extra_kwargs)
         self.__transport = transport
 
         self.__encoding = encoding or 'utf-8'
index e69f91924c47063182017b5abbbe85c773e7f187..924a8a205353d5a789cf839670b92a7047253c8b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -36,6 +36,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #22960: Add a context argument to xmlrpclib.ServerProxy constructor.
+
 - Issue #22915: SAX parser now supports files opened with file descriptor or
   bytes path.