77This module returns the installation location of cacert.pem or its contents.
88"""
99import os
10+ import types
11+ from typing import Union
1012
1113try :
1214 from importlib .resources import path as get_path , read_text
1315
1416 _CACERT_CTX = None
1517 _CACERT_PATH = None
1618
17- def where ():
19+ def where () -> str :
1820 # This is slightly terrible, but we want to delay extracting the file
1921 # in cases where we're inside of a zipimport situation until someone
2022 # actually calls where(), but we don't want to re-extract the file
@@ -40,21 +42,29 @@ def where():
4042
4143
4244except ImportError :
45+ Package = Union [types .ModuleType , str ]
46+ Resource = Union [str , "os.PathLike" ]
47+
4348 # This fallback will work for Python versions prior to 3.7 that lack the
4449 # importlib.resources module but relies on the existing `where` function
4550 # so won't address issues with environments like PyOxidizer that don't set
4651 # __file__ on modules.
47- def read_text (_module , _path , encoding = "ascii" ):
52+ def read_text (
53+ package : Package ,
54+ resource : Resource ,
55+ encoding : str = 'utf-8' ,
56+ errors : str = 'strict'
57+ ) -> str :
4858 with open (where (), "r" , encoding = encoding ) as data :
4959 return data .read ()
5060
5161 # If we don't have importlib.resources, then we will just do the old logic
5262 # of assuming we're on the filesystem and munge the path directly.
53- def where ():
63+ def where () -> str :
5464 f = os .path .dirname (__file__ )
5565
5666 return os .path .join (f , "cacert.pem" )
5767
5868
59- def contents ():
69+ def contents () -> str :
6070 return read_text ("certifi" , "cacert.pem" , encoding = "ascii" )
0 commit comments