Skip to content

Commit 4d80f04

Browse files
encukoumcepl
authored andcommitted
Implement PEP 706 – Filter for tarfile.extractall
1 parent 8d999cb commit 4d80f04

File tree

7 files changed

+1750
-95
lines changed

7 files changed

+1750
-95
lines changed

Doc/library/shutil.rst

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
537537
Remove the archive format *name* from the list of supported formats.
538538

539539

540-
.. function:: unpack_archive(filename[, extract_dir[, format]])
540+
.. function:: unpack_archive(filename[, extract_dir[, format[, filter]]])
541541

542542
Unpack an archive. *filename* is the full path of the archive.
543543

@@ -551,6 +551,16 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
551551
registered for that extension. In case none is found,
552552
a :exc:`ValueError` is raised.
553553

554+
The keyword-only *filter* argument is passed to the underlying unpacking
555+
function. For zip files, *filter* is not accepted.
556+
For tar files, it is recommended to set it to ``'data'``,
557+
unless using features specific to tar and UNIX-like filesystems.
558+
(See :ref:`tarfile-extraction-filter` for details.)
559+
The ``'data'`` filter will become the default for tar files
560+
in Python 3.14.
561+
562+
.. versionchanged:: 3.6.16
563+
Added the *filter* argument.
554564

555565
.. function:: register_unpack_format(name, extensions, function[, extra_args[, description]])
556566

@@ -559,11 +569,14 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
559569
``.zip`` for Zip files.
560570

561571
*function* is the callable that will be used to unpack archives. The
562-
callable will receive the path of the archive, followed by the directory
563-
the archive must be extracted to.
564-
565-
When provided, *extra_args* is a sequence of ``(name, value)`` tuples that
566-
will be passed as keywords arguments to the callable.
572+
callable will receive:
573+
574+
- the path of the archive, as a positional argument;
575+
- the directory the archive must be extracted to, as a positional argument;
576+
- possibly a *filter* keyword argument, if it was given to
577+
:func:`unpack_archive`;
578+
- additional keyword arguments, specified by *extra_args* as a sequence
579+
of ``(name, value)`` tuples.
567580

568581
*description* can be provided to describe the format, and will be returned
569582
by the :func:`get_unpack_formats` function.

0 commit comments

Comments
 (0)