Skip to content

Commit 6b2e193

Browse files
committed
get.py tarfile py3.12 extraction filter=...
https://docs.python.org/3/library/tarfile.html#tarfile.TarFile.extraction_filter > If extraction_filter is None (the default), calling an extraction method without a filter argument > will raise a DeprecationWarning, and fall back to the fully_trusted filter, whose dangerous > behavior matches previous versions of Python.
1 parent ea43050 commit 6b2e193

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

tools/get.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818

1919
verbose = True
2020

21-
if sys.version_info[0] == 3:
22-
from urllib.request import urlretrieve
21+
from urllib.request import urlretrieve
22+
23+
if sys.version_info >= (3,12):
24+
TARFILE_EXTRACT_ARGS = {'filter': 'data'}
2325
else:
24-
# Not Python 3 - today, it is most likely to be Python 2
25-
from urllib import urlretrieve
26+
TARFILE_EXTRACT_ARGS = {}
2627

2728
dist_dir = 'dist/'
2829

@@ -51,9 +52,10 @@ def report_progress(count, blockSize, totalSize):
5152
def unpack(filename, destination):
5253
dirname = ''
5354
print('Extracting {0}'.format(filename))
54-
if filename.endswith('tar.gz'):
55-
tfile = tarfile.open(filename, 'r:gz')
56-
tfile.extractall(destination)
55+
extension = filename.split('.')[-1]
56+
if filename.endswith((f'.tar.{extension}', f'.t{extension}')):
57+
tfile = tarfile.open(filename, f'r:{extension}')
58+
tfile.extractall(destination, **TARFILE_EXTRACT_ARGS)
5759
dirname= tfile.getnames()[0]
5860
elif filename.endswith('zip'):
5961
zfile = zipfile.ZipFile(filename)

0 commit comments

Comments
 (0)