From 90e6a523ead7fe0245b85567a402dbdf380750a0 Mon Sep 17 00:00:00 2001 From: Jack O'Connor Date: Wed, 4 Dec 2024 10:44:46 -0800 Subject: [PATCH] use the new `filter` argument with TarFile.extractall on Python 3.12+ --- peru/resources/plugins/curl/curl_plugin.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/peru/resources/plugins/curl/curl_plugin.py b/peru/resources/plugins/curl/curl_plugin.py index 668428d..05265d8 100755 --- a/peru/resources/plugins/curl/curl_plugin.py +++ b/peru/resources/plugins/curl/curl_plugin.py @@ -130,7 +130,16 @@ def extract_tar(archive_path, dest): validate_filename(info.path) if info.issym(): validate_symlink(info.path, info.linkname) - t.extractall(dest) + # Python 3.12 added the `filter` kwarg, which should make our + # validation redundant. (It was also added to patch releases of earlier + # Python versions.) Python 3.13 made it a warning to omit this + # argument, because Python 3.14 will change the default to "data". + # That's the behavior we want, and specifying it here lets us get it on + # Python 3.12/3.13 and silences the warning. + kwargs = {} + if sys.version_info >= (3, 12): + kwargs["filter"] = "data" + t.extractall(dest, **kwargs) def extract_zip(archive_path, dest):