Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/httplib2-0.22.0-py3.8.egg/httplib2/certs.py: 72%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

29 statements  

1"""Utilities for certificate management.""" 

2 

3import os 

4 

5certifi_available = False 

6certifi_where = None 

7try: 

8 from certifi import where as certifi_where 

9 certifi_available = True 

10except ImportError: 

11 pass 

12 

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 

20 

21 

22BUILTIN_CA_CERTS = os.path.join( 

23 os.path.dirname(os.path.abspath(__file__)), "cacerts.txt" 

24) 

25 

26 

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 

39 

40 

41if __name__ == "__main__": 

42 print(where())