@@ -620,7 +620,7 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
620
620
Remove the archive format *name* from the list of supported formats.
621
621
622
622
623
- .. function:: unpack_archive(filename[, extract_dir[, format]])
623
+ .. function:: unpack_archive(filename[, extract_dir[, format[, filter] ]])
624
624
625
625
Unpack an archive. *filename* is the full path of the archive.
626
626
@@ -634,6 +634,15 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
634
634
registered for that extension. In case none is found,
635
635
a :exc:`ValueError` is raised.
636
636
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
+
637
646
.. audit-event:: shutil.unpack_archive filename,extract_dir,format shutil.unpack_archive
638
647
639
648
.. warning::
@@ -646,18 +655,24 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
646
655
.. versionchanged:: 3.7
647
656
Accepts a :term:`path-like object` for *filename* and *extract_dir*.
648
657
658
+ .. versionchanged:: 3.10.12
659
+ Added the *filter* argument.
660
+
649
661
.. function:: register_unpack_format(name, extensions, function[, extra_args[, description]])
650
662
651
663
Registers an unpack format. *name* is the name of the format and
652
664
*extensions* is a list of extensions corresponding to the format, like
653
665
``.zip`` for Zip files.
654
666
655
667
*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.
661
676
662
677
*description* can be provided to describe the format, and will be returned
663
678
by the :func:`get_unpack_formats` function.
0 commit comments