Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
| 1 |
"""Utilities for certificate management.""" |
| 2 |
|
| 3 |
import os |
| 4 |
|
| 5 |
certifi_available = False |
| 6 |
certifi_where = None |
| 7 |
try: |
| 8 |
from certifi import where as certifi_where |
| 9 |
certifi_available = True |
| 10 |
except ImportError: |
| 11 |
pass |
| 12 |
|
| 13 |
custom_ca_locater_available = False |
| 14 |
custom_ca_locater_where = None |
| 15 |
try: |
| 16 |
from ca_certs_locater import get as custom_ca_locater_where |
| 17 |
custom_ca_locater_available = True |
| 18 |
except ImportError: |
| 19 |
pass |
| 20 |
|
| 21 |
|
| 22 |
BUILTIN_CA_CERTS = os.path.join( |
| 23 |
os.path.dirname(os.path.abspath(__file__)), "cacerts.txt" |
| 24 |
) |
| 25 |
|
| 26 |
|
| 27 |
def where(): |
| 28 |
env = os.environ.get("HTTPLIB2_CA_CERTS") |
| 29 |
if env is not None: |
| 30 |
if os.path.isfile(env): |
| 31 |
return env |
| 32 |
else: |
| 33 |
raise RuntimeError("Environment variable HTTPLIB2_CA_CERTS not a valid file") |
| 34 |
if custom_ca_locater_available: |
| 35 |
return custom_ca_locater_where() |
| 36 |
if certifi_available: |
| 37 |
return certifi_where() |
| 38 |
return BUILTIN_CA_CERTS |
| 39 |
|
| 40 |
|
| 41 |
if __name__ == "__main__": |
| 42 |
print(where()) |