Skip to content

Commit 425065b

Browse files
mceplencukou
andauthored
[3.10] pythongh-102950: Implement PEP 706 – Filter for tarfile.extractall (pythonGH-102953) (pythonGH-104128)
- Backport b52ad18 - Backport c8c3956 - Remove the DeprecationWarning - Adjust docs - Remove new `__all__` entries Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent cfa4295 commit 425065b

File tree

8 files changed

+1788
-97
lines changed

8 files changed

+1788
-97
lines changed

Doc/library/shutil.rst

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

622622

623-
.. function:: unpack_archive(filename[, extract_dir[, format]])
623+
.. function:: unpack_archive(filename[, extract_dir[, format[, filter]]])
624624

625625
Unpack an archive. *filename* is the full path of the archive.
626626

@@ -634,6 +634,15 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
634634
registered for that extension. In case none is found,
635635
a :exc:`ValueError` is raised.
636636

637+
The keyword-only *filter* argument, which was added in Python 3.10.12,
638+
is passed to the underlying unpacking function.
639+
For zip files, *filter* is not accepted.
640+
For tar files, it is recommended to set it to ``'data'``,
641+
unless using features specific to tar and UNIX-like filesystems.
642+
(See :ref:`tarfile-extraction-filter` for details.)
643+
The ``'data'`` filter will become the default for tar files
644+
in Python 3.14.
645+
637646
.. audit-event:: shutil.unpack_archive filename,extract_dir,format shutil.unpack_archive
638647

639648
.. warning::
@@ -646,18 +655,24 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
646655
.. versionchanged:: 3.7
647656
Accepts a :term:`path-like object` for *filename* and *extract_dir*.
648657

658+
.. versionchanged:: 3.10.12
659+
Added the *filter* argument.
660+
649661
.. function:: register_unpack_format(name, extensions, function[, extra_args[, description]])
650662

651663
Registers an unpack format. *name* is the name of the format and
652664
*extensions* is a list of extensions corresponding to the format, like
653665
``.zip`` for Zip files.
654666

655667
*function* is the callable that will be used to unpack archives. The
656-
callable will receive the path of the archive, followed by the directory
657-
the archive must be extracted to.
658-
659-
When provided, *extra_args* is a sequence of ``(name, value)`` tuples that
660-
will be passed as keywords arguments to the callable.
668+
callable will receive:
669+
670+
- the path of the archive, as a positional argument;
671+
- the directory the archive must be extracted to, as a positional argument;
672+
- possibly a *filter* keyword argument, if it was given to
673+
:func:`unpack_archive`;
674+
- additional keyword arguments, specified by *extra_args* as a sequence
675+
of ``(name, value)`` tuples.
661676

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy