Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/requests_toolbelt/adapters/fingerprint.py @ 5:9b1c78e6ba9c draft default tip
"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
| author | shellac |
|---|---|
| date | Mon, 01 Jun 2020 08:59:25 -0400 |
| parents | 79f47841a781 |
| children |
comparison
equal
deleted
inserted
replaced
| 4:79f47841a781 | 5:9b1c78e6ba9c |
|---|---|
| 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) |
