Updated Requests api to accept a 'cert' argument.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
This argument can be either a string, containing the path to a pem-formatted key and certificate chain, or a tuple of (cert, key). When supplied a tuple, the values are paths to an SSL certificate chain file and key, respectively.
authored by chadnickbok@gmail.com · committed by chadnickbok@gmail.com · parent 82e69de · Browse files · 3 files·+17 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+17 added−19 removed
- other:+17 added−19 removed
Provenance
- Commit
fc618aa- Tree
f5e8726- Author
chadnickbok@gmail.com <chad@gaikai.com>- Committer
chadnickbok@gmail.com <chad@gaikai.com>- Parent
82e69de
3 files changed+17 added−19 removed
modified:requests/api.py+1 added-2 removed
31 unmodified lines32 :param session: (optional) A :class:`Session` object to be used for the request.33 :param config: (optional) A configuration dictionary.34 :param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided.35 :param prefetch: (optional) if ``True``, the response content will be immediately downloaded.36- :param key_file: (optional) ssl client key file.37- :param cert_file: (optional) ssl client cert file.36+ :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.37 """38 39 s = kwargs.pop('session') if 'session' in kwargs else sessions.session()40 return s.request(method=method, url=url, **kwargs)77 unmodified linesmodified:requests/models.py+10 added-8 removed
62 unmodified lines63 config=None,64 _poolmanager=None,65 verify=None,66 session=None,67- key_file=None,68- cert_file=None):67+ cert=None):68 69 #: Dictionary of configurations for this request.70 self.config = dict(config or [])71 72 unmodified lines144 #: SSL Verification.145 self.verify = verify146 147 #: SSL Certificate149- self.key_file = key_file150- self.cert_file = cert_file148+ self.cert = cert149 150 if headers:151 headers = CaseInsensitiveDict(self.headers)152 else:117 unmodified lines270 timeout=self.timeout,271 _poolmanager=self._poolmanager,272 proxies=self.proxies,273 verify=self.verify,276- session=self.session274+ session=self.session,275+ cert=self.cert276 )277 278 request.send()279 r = request.response231 unmodified lines511 else:512 conn.cert_reqs = 'CERT_NONE'513 conn.ca_certs = None514 516- if self.key_file and self.cert_file:517- conn.key_file = self.key_file518- conn.cert_file = self.cert_file515+ if self.cert:516+ if type(self.cert) is tuple:517+ conn.cert_file = self.cert[0]518+ conn.key_file = self.cert[1]519+ else:520+ conn.cert_file = self.cert521 522 if not self.sent or anyway:523 524 if self.cookies:304 unmodified linesmodified:requests/sessions.py+6 added-9 removed
62 unmodified lines63 """A Requests session."""64 65 __attrs__ = [66 'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks',67- 'params', 'config', 'verify']67+ 'params', 'config', 'verify', 'cert']68 69 70 def __init__(self,71 headers=None,5 unmodified lines77 params=None,78 config=None,79 prefetch=False,80 verify=True,81- key_file=None,82- cert_file=None):81+ cert=None):82 83 self.headers = headers or {}84 self.cookies = cookies or {}85 self.auth = auth3 unmodified lines89 self.params = params or {}90 self.config = config or {}91 self.prefetch = prefetch92 self.verify = verify94- self.key_file = key_file95- self.cert_file = cert_file93+ self.cert = cert94 95 for (k, v) in list(defaults.items()):96 self.config.setdefault(k, v)97 35 unmodified lines133 return_response=True,134 config=None,135 prefetch=False,136 verify=None,139- key_file=None,140- cert_file=None):137+ cert=None):138 139 """Constructs and sends a :class:`Request <Request>`.140 Returns :class:`Response <Response>` object.141 11 unmodified lines153 :param return_response: (optional) If False, an un-sent Request object will returned.154 :param config: (optional) A configuration dictionary.155 :param prefetch: (optional) if ``True``, the response content will be immediately downloaded.156 :param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided.157+ :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.158 """159 160 method = str(method).upper()161 29 unmodified lines191 allow_redirects=allow_redirects,192 proxies=proxies,193 config=config,194 verify=verify,197- key_file=key_file,198- cert_file=cert_file,195+ cert=cert,196 _poolmanager=self.poolmanager197 )198 199 # Merge local kwargs with session kwargs.118 unmodified lines