]>
jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/pip/_vendor/certifi/core.py
5 This module returns the installation location of cacert.pem or its contents.
10 if sys
.version_info
>= (3, 11):
12 from importlib
.resources
import as_file
, files
18 # This is slightly terrible, but we want to delay extracting the file
19 # in cases where we're inside of a zipimport situation until someone
20 # actually calls where(), but we don't want to re-extract the file
21 # on every call of where(), so we'll do it once then store it in a
25 if _CACERT_PATH
is None:
26 # This is slightly janky, the importlib.resources API wants you to
27 # manage the cleanup of this file, so it doesn't actually return a
28 # path, it returns a context manager that will give you the path
29 # when you enter it and will do any cleanup when you leave it. In
30 # the common case of not needing a temporary file, it will just
31 # return the file system location and the __exit__() is a no-op.
33 # We also have to hold onto the actual context manager, because
34 # it will do the cleanup whenever it gets garbage collected, so
35 # we will also store that at the global level as well.
36 _CACERT_CTX
= as_file(files("pip._vendor.certifi").joinpath("cacert.pem"))
37 _CACERT_PATH
= str(_CACERT_CTX
.__enter
__())
41 def contents() -> str:
42 return files("pip._vendor.certifi").joinpath("cacert.pem").read_text(encoding
="ascii")
44 elif sys
.version_info
>= (3, 7):
46 from importlib
.resources
import path
as get_path
, read_text
52 # This is slightly terrible, but we want to delay extracting the
53 # file in cases where we're inside of a zipimport situation until
54 # someone actually calls where(), but we don't want to re-extract
55 # the file on every call of where(), so we'll do it once then store
56 # it in a global variable.
59 if _CACERT_PATH
is None:
60 # This is slightly janky, the importlib.resources API wants you
61 # to manage the cleanup of this file, so it doesn't actually
62 # return a path, it returns a context manager that will give
63 # you the path when you enter it and will do any cleanup when
64 # you leave it. In the common case of not needing a temporary
65 # file, it will just return the file system location and the
66 # __exit__() is a no-op.
68 # We also have to hold onto the actual context manager, because
69 # it will do the cleanup whenever it gets garbage collected, so
70 # we will also store that at the global level as well.
71 _CACERT_CTX
= get_path("pip._vendor.certifi", "cacert.pem")
72 _CACERT_PATH
= str(_CACERT_CTX
.__enter
__())
76 def contents() -> str:
77 return read_text("pip._vendor.certifi", "cacert.pem", encoding
="ascii")
82 from typing
import Union
84 Package
= Union
[types
.ModuleType
, str]
85 Resource
= Union
[str, "os.PathLike"]
87 # This fallback will work for Python versions prior to 3.7 that lack the
88 # importlib.resources module but relies on the existing `where` function
89 # so won't address issues with environments like PyOxidizer that don't set
90 # __file__ on modules.
94 encoding
: str = 'utf-8',
95 errors
: str = 'strict'
97 with open(where(), encoding
=encoding
) as data
:
100 # If we don't have importlib.resources, then we will just do the old logic
101 # of assuming we're on the filesystem and munge the path directly.
103 f
= os
.path
.dirname(__file__
)
105 return os
.path
.join(f
, "cacert.pem")
107 def contents() -> str:
108 return read_text("pip._vendor.certifi", "cacert.pem", encoding
="ascii")