comparison venv/lib/python2.7/site-packages/requests_toolbelt/adapters/fingerprint.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 """Submodule containing the implementation for the FingerprintAdapter.
3
4 This file contains an implementation of a Transport Adapter that validates
5 the fingerprints of SSL certificates presented upon connection.
6 """
7 from requests.adapters import HTTPAdapter
8 from requests.packages.urllib3.poolmanager import PoolManager
9
10
11 class FingerprintAdapter(HTTPAdapter):
12 """
13 A HTTPS Adapter for Python Requests that verifies certificate fingerprints,
14 instead of certificate hostnames.
15
16 Example usage:
17
18 .. code-block:: python
19
20 import requests
21 import ssl
22 from requests_toolbelt.adapters.fingerprint import FingerprintAdapter
23
24 twitter_fingerprint = '...'
25 s = requests.Session()
26 s.mount(
27 'https://twitter.com',
28 FingerprintAdapter(twitter_fingerprint)
29 )
30
31 The fingerprint should be provided as a hexadecimal string, optionally
32 containing colons.
33 """
34
35 __attrs__ = HTTPAdapter.__attrs__ + ['fingerprint']
36
37 def __init__(self, fingerprint, **kwargs):
38 self.fingerprint = fingerprint
39
40 super(FingerprintAdapter, self).__init__(**kwargs)
41
42 def init_poolmanager(self, connections, maxsize, block=False):
43 self.poolmanager = PoolManager(num_pools=connections,
44 maxsize=maxsize,
45 block=block,
46 assert_fingerprint=self.fingerprint)