comparison env/lib/python3.7/site-packages/requests_toolbelt/adapters/fingerprint.py @ 0:26e78fe6e8c4 draft

"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author shellac
date Sat, 02 May 2020 07:14:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:26e78fe6e8c4
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
9 from .._compat import poolmanager
10
11
12 class FingerprintAdapter(HTTPAdapter):
13 """
14 A HTTPS Adapter for Python Requests that verifies certificate fingerprints,
15 instead of certificate hostnames.
16
17 Example usage:
18
19 .. code-block:: python
20
21 import requests
22 import ssl
23 from requests_toolbelt.adapters.fingerprint import FingerprintAdapter
24
25 twitter_fingerprint = '...'
26 s = requests.Session()
27 s.mount(
28 'https://twitter.com',
29 FingerprintAdapter(twitter_fingerprint)
30 )
31
32 The fingerprint should be provided as a hexadecimal string, optionally
33 containing colons.
34 """
35
36 __attrs__ = HTTPAdapter.__attrs__ + ['fingerprint']
37
38 def __init__(self, fingerprint, **kwargs):
39 self.fingerprint = fingerprint
40
41 super(FingerprintAdapter, self).__init__(**kwargs)
42
43 def init_poolmanager(self, connections, maxsize, block=False):
44 self.poolmanager = poolmanager.PoolManager(
45 num_pools=connections,
46 maxsize=maxsize,
47 block=block,
48 assert_fingerprint=self.fingerprint)