Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/requests_toolbelt/adapters/fingerprint.py @ 2:6af9afd405e9 draft
"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
author | shellac |
---|---|
date | Thu, 14 May 2020 14:56:58 -0400 |
parents | 26e78fe6e8c4 |
children |
comparison
equal
deleted
inserted
replaced
1:75ca89e9b81c | 2:6af9afd405e9 |
---|---|
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) |