Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c1da3d1

Browse files
committed
add context parameter to xmlrpclib.ServerProxy (#22960)
Patch by Alex Gaynor.
1 parent 2b3b95b commit c1da3d1

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

Doc/library/xmlrpc.client.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ between conformable Python objects and XML on the wire.
3434

3535
.. class:: ServerProxy(uri, transport=None, encoding=None, verbose=False, \
3636
allow_none=False, use_datetime=False, \
37-
use_builtin_types=False)
37+
use_builtin_types=False, context=None)
3838

3939
.. versionchanged:: 3.3
4040
The *use_builtin_types* flag was added.
@@ -63,7 +63,9 @@ between conformable Python objects and XML on the wire.
6363
portion will be base64-encoded as an HTTP 'Authorization' header, and sent to
6464
the remote server as part of the connection process when invoking an XML-RPC
6565
method. You only need to use this if the remote server requires a Basic
66-
Authentication user and password.
66+
Authentication user and password. If an HTTPS url is provided, *context* may
67+
be :class:`ssl.SSLContext` and configures the SSL settings of the underlying
68+
HTTPS connection.
6769

6870
The returned instance is a proxy object with methods that can be used to invoke
6971
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.
127129
:class:`Server` is retained as an alias for :class:`ServerProxy` for backwards
128130
compatibility. New code should use :class:`ServerProxy`.
129131

132+
.. versionchanged:: 3.4.3
133+
Added the *context* argument.
134+
130135

131136
.. seealso::
132137

Lib/xmlrpc/client.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,11 @@ def parse_response(self, response):
13231323
class SafeTransport(Transport):
13241324
"""Handles an HTTPS transaction to an XML-RPC server."""
13251325

1326+
def __init__(self, use_datetime=False, use_builtin_types=False, *,
1327+
context=None):
1328+
super().__init__(use_datetime=use_datetime, use_builtin_types=use_builtin_types)
1329+
self.context = context
1330+
13261331
# FIXME: mostly untested
13271332

13281333
def make_connection(self, host):
@@ -1336,7 +1341,7 @@ def make_connection(self, host):
13361341
# host may be a string, or a (host, x509-dict) tuple
13371342
chost, self._extra_headers, x509 = self.get_host_info(host)
13381343
self._connection = host, http.client.HTTPSConnection(chost,
1339-
None, **(x509 or {}))
1344+
None, context=self.context, **(x509 or {}))
13401345
return self._connection[1]
13411346

13421347
##
@@ -1379,7 +1384,8 @@ class ServerProxy:
13791384
"""
13801385

13811386
def __init__(self, uri, transport=None, encoding=None, verbose=False,
1382-
allow_none=False, use_datetime=False, use_builtin_types=False):
1387+
allow_none=False, use_datetime=False, use_builtin_types=False,
1388+
*, context=None):
13831389
# establish a "logical" server connection
13841390

13851391
# get the url
@@ -1393,10 +1399,13 @@ def __init__(self, uri, transport=None, encoding=None, verbose=False,
13931399
if transport is None:
13941400
if type == "https":
13951401
handler = SafeTransport
1402+
extra_kwargs = {"context": context}
13961403
else:
13971404
handler = Transport
1405+
extra_kwargs = {}
13981406
transport = handler(use_datetime=use_datetime,
1399-
use_builtin_types=use_builtin_types)
1407+
use_builtin_types=use_builtin_types,
1408+
**extra_kwargs)
14001409
self.__transport = transport
14011410

14021411
self.__encoding = encoding or 'utf-8'

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Core and Builtins
3636
Library
3737
-------
3838

39+
- Issue #22960: Add a context argument to xmlrpclib.ServerProxy constructor.
40+
3941
- Issue #22915: SAX parser now supports files opened with file descriptor or
4042
bytes path.
4143

0 commit comments

Comments
 (0)