comparison venv/lib/python2.7/site-packages/requests_toolbelt/adapters/ssl.py @ 0:d67268158946 draft

planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author bcclaywell
date Mon, 12 Oct 2015 17:43:33 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d67268158946
1 # -*- coding: utf-8 -*-
2 """
3
4 requests_toolbelt.ssl_adapter
5 =============================
6
7 This file contains an implementation of the SSLAdapter originally demonstrated
8 in this blog post:
9 https://lukasa.co.uk/2013/01/Choosing_SSL_Version_In_Requests/
10
11 """
12 from requests.adapters import HTTPAdapter
13 from requests.packages.urllib3.poolmanager import PoolManager
14
15
16 class SSLAdapter(HTTPAdapter):
17 """
18 A HTTPS Adapter for Python Requests that allows the choice of the SSL/TLS
19 version negotiated by Requests. This can be used either to enforce the
20 choice of high-security TLS versions (where supported), or to work around
21 misbehaving servers that fail to correctly negotiate the default TLS
22 version being offered.
23
24 Example usage:
25
26 >>> import requests
27 >>> import ssl
28 >>> from requests_toolbelt import SSLAdapter
29 >>> s = requests.Session()
30 >>> s.mount('https://', SSLAdapter(ssl.PROTOCOL_TLSv1))
31
32 You can replace the chosen protocol with any that are available in the
33 default Python SSL module. All subsequent requests that match the adapter
34 prefix will use the chosen SSL version instead of the default.
35 """
36
37 __attrs__ = HTTPAdapter.__attrs__ + ['ssl_version']
38
39 def __init__(self, ssl_version=None, **kwargs):
40 self.ssl_version = ssl_version
41
42 super(SSLAdapter, self).__init__(**kwargs)
43
44 def init_poolmanager(self, connections, maxsize, block=False):
45 self.poolmanager = PoolManager(num_pools=connections,
46 maxsize=maxsize,
47 block=block,
48 ssl_version=self.ssl_version)