@@ -471,7 +471,7 @@ class Context(object):
471
471
"""
472
472
def __init__ (self , handler = None , ** kwargs ):
473
473
self .http = HttpLib (handler , kwargs .get ("verify" , False ), key_file = kwargs .get ("key_file" ),
474
- cert_file = kwargs .get ("cert_file" )) # Default to False for backward compat
474
+ cert_file = kwargs .get ("cert_file" ), context = kwargs . get ( "context" ) ) # Default to False for backward compat
475
475
self .token = kwargs .get ("token" , _NoAuthenticationToken )
476
476
if self .token is None : # In case someone explicitly passes token=None
477
477
self .token = _NoAuthenticationToken
@@ -1137,9 +1137,9 @@ class HttpLib(object):
1137
1137
1138
1138
If using the default handler, SSL verification can be disabled by passing verify=False.
1139
1139
"""
1140
- def __init__ (self , custom_handler = None , verify = False , key_file = None , cert_file = None ):
1140
+ def __init__ (self , custom_handler = None , verify = False , key_file = None , cert_file = None , context = None ):
1141
1141
if custom_handler is None :
1142
- self .handler = handler (verify = verify , key_file = key_file , cert_file = cert_file )
1142
+ self .handler = handler (verify = verify , key_file = key_file , cert_file = cert_file , context = context )
1143
1143
else :
1144
1144
self .handler = custom_handler
1145
1145
self ._cookies = {}
@@ -1351,7 +1351,7 @@ def readinto(self, byte_array):
1351
1351
return bytes_read
1352
1352
1353
1353
1354
- def handler (key_file = None , cert_file = None , timeout = None , verify = False ):
1354
+ def handler (key_file = None , cert_file = None , timeout = None , verify = False , context = None ):
1355
1355
"""This class returns an instance of the default HTTP request handler using
1356
1356
the values you provide.
1357
1357
@@ -1363,6 +1363,8 @@ def handler(key_file=None, cert_file=None, timeout=None, verify=False):
1363
1363
:type timeout: ``integer`` or "None"
1364
1364
:param `verify`: Set to False to disable SSL verification on https connections.
1365
1365
:type verify: ``Boolean``
1366
+ :param `context`: The SSLContext that can is used with the HTTPSConnection when verify=True is enabled and context is specified
1367
+ :type context: ``SSLContext`
1366
1368
"""
1367
1369
1368
1370
def connect (scheme , host , port ):
@@ -1376,6 +1378,10 @@ def connect(scheme, host, port):
1376
1378
1377
1379
if not verify :
1378
1380
kwargs ['context' ] = ssl ._create_unverified_context ()
1381
+ elif context :
1382
+ # verify is True in elif branch and context is not None
1383
+ kwargs ['context' ] = context
1384
+
1379
1385
return six .moves .http_client .HTTPSConnection (host , port , ** kwargs )
1380
1386
raise ValueError ("unsupported scheme: %s" % scheme )
1381
1387
0 commit comments