From 280b9b7cb0713e20db9679dff29738a710c146f5 Mon Sep 17 00:00:00 2001 From: luccabb Date: Tue, 30 Jan 2024 15:54:36 +0000 Subject: [PATCH 1/3] fix leaking certificate issue --- certifi/core.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/certifi/core.py b/certifi/core.py index de028981..c8726241 100644 --- a/certifi/core.py +++ b/certifi/core.py @@ -5,6 +5,10 @@ This module returns the installation location of cacert.pem or its contents. """ import sys +import atexit + +def exit_cacert_ctx() -> None: + _CACERT_CTX.__exit__(None, None, None) if sys.version_info >= (3, 11): @@ -35,6 +39,7 @@ def where() -> str: # we will also store that at the global level as well. _CACERT_CTX = as_file(files("certifi").joinpath("cacert.pem")) _CACERT_PATH = str(_CACERT_CTX.__enter__()) + atexit.register(exit_cacert_ctx) return _CACERT_PATH @@ -70,6 +75,7 @@ def where() -> str: # we will also store that at the global level as well. _CACERT_CTX = get_path("certifi", "cacert.pem") _CACERT_PATH = str(_CACERT_CTX.__enter__()) + atexit.register(exit_cacert_ctx) return _CACERT_PATH From ea16e5e3fe5b31472d8e25e744c2433282d9dc63 Mon Sep 17 00:00:00 2001 From: luccabb Date: Tue, 30 Jan 2024 16:03:59 +0000 Subject: [PATCH 2/3] mypy --- certifi/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/certifi/core.py b/certifi/core.py index c8726241..8702ea77 100644 --- a/certifi/core.py +++ b/certifi/core.py @@ -8,7 +8,7 @@ import atexit def exit_cacert_ctx() -> None: - _CACERT_CTX.__exit__(None, None, None) + _CACERT_CTX.__exit__(None, None, None) # type: ignore[attr-defined] if sys.version_info >= (3, 11): From 033e71d304a3715c4a6d9ac61e064e1a9305a463 Mon Sep 17 00:00:00 2001 From: luccabb Date: Tue, 30 Jan 2024 16:06:47 +0000 Subject: [PATCH 3/3] mypy ignore --- certifi/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/certifi/core.py b/certifi/core.py index 8702ea77..91f538bb 100644 --- a/certifi/core.py +++ b/certifi/core.py @@ -8,7 +8,7 @@ import atexit def exit_cacert_ctx() -> None: - _CACERT_CTX.__exit__(None, None, None) # type: ignore[attr-defined] + _CACERT_CTX.__exit__(None, None, None) # type: ignore[union-attr] if sys.version_info >= (3, 11):