MCPcopy Create free account
hub / github.com/certifi/python-certifi / where

Function where

certifi/core.py:21–44  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19 _CACERT_PATH = None
20
21 def where() -> str:
22 # This is slightly terrible, but we want to delay extracting the file
23 # in cases where we're inside of a zipimport situation until someone
24 # actually calls where(), but we don't want to re-extract the file
25 # on every call of where(), so we'll do it once then store it in a
26 # global variable.
27 global _CACERT_CTX
28 global _CACERT_PATH
29 if _CACERT_PATH is None:
30 # This is slightly janky, the importlib.resources API wants you to
31 # manage the cleanup of this file, so it doesn't actually return a
32 # path, it returns a context manager that will give you the path
33 # when you enter it and will do any cleanup when you leave it. In
34 # the common case of not needing a temporary file, it will just
35 # return the file system location and the __exit__() is a no-op.
36 #
37 # We also have to hold onto the actual context manager, because
38 # it will do the cleanup whenever it gets garbage collected, so
39 # we will also store that at the global level as well.
40 _CACERT_CTX = as_file(files("certifi").joinpath("cacert.pem"))
41 _CACERT_PATH = str(_CACERT_CTX.__enter__())
42 atexit.register(exit_cacert_ctx)
43
44 return _CACERT_PATH
45
46 def contents() -> str:
47 return files("certifi").joinpath("cacert.pem").read_text(encoding="ascii")

Callers 1

__main__.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected