Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/httplib2/certs.py: 69%
29 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:51 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:51 +0000
1"""Utilities for certificate management."""
3import os
5certifi_available = False
6certifi_where = None
7try:
8 from certifi import where as certifi_where
9 certifi_available = True
10except ImportError:
11 pass
13custom_ca_locater_available = False
14custom_ca_locater_where = None
15try:
16 from ca_certs_locater import get as custom_ca_locater_where
17 custom_ca_locater_available = True
18except ImportError:
19 pass
22BUILTIN_CA_CERTS = os.path.join(
23 os.path.dirname(os.path.abspath(__file__)), "cacerts.txt"
24)
27def 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
41if __name__ == "__main__":
42 print(where())