This commit is contained in:
2026-01-31 15:37:17 -08:00
parent ae7acd48ac
commit c854f8c6a8
5 changed files with 151 additions and 7 deletions

View File

@@ -52,12 +52,22 @@ def _resolve_verify_value(verify_ssl: bool) -> Union[bool, str]:
def _try_module_bundle(mod_name: str) -> Optional[str]:
# Prefer checking sys.modules first (helps test injection / monkeypatching)
try:
mod = sys.modules.get(mod_name)
if mod is None:
mod = __import__(mod_name)
except (ImportError, ModuleNotFoundError):
return None
mod = sys.modules.get(mod_name)
if mod is None:
# Avoid raising ModuleNotFoundError so debuggers and callers aren't interrupted.
# Check for module availability before attempting to import it.
try:
import importlib.util
spec = importlib.util.find_spec(mod_name)
if spec is None:
return None
import importlib
mod = importlib.import_module(mod_name)
except Exception:
# Treat any import/initialization failure as module not available.
return None
# Common APIs that return a bundle path
for attr in ("where", "get_ca_bundle", "bundle_path", "get_bundle_path", "get_bundle"):