@@ -614,7 +614,7 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
614
614
Remove the archive format *name * from the list of supported formats.
615
615
616
616
617
- .. function :: unpack_archive(filename[, extract_dir[, format]])
617
+ .. function :: unpack_archive(filename[, extract_dir[, format[, filter] ]])
618
618
619
619
Unpack an archive. *filename * is the full path of the archive.
620
620
@@ -628,6 +628,15 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
628
628
registered for that extension. In case none is found,
629
629
a :exc: `ValueError ` is raised.
630
630
631
+ The keyword-only *filter * argument, which was added in Python 3.9.17,
632
+ is passed to the underlying unpacking function.
633
+ For zip files, *filter * is not accepted.
634
+ For tar files, it is recommended to set it to ``'data' ``,
635
+ unless using features specific to tar and UNIX-like filesystems.
636
+ (See :ref: `tarfile-extraction-filter ` for details.)
637
+ The ``'data' `` filter will become the default for tar files
638
+ in Python 3.14.
639
+
631
640
.. audit-event :: shutil.unpack_archive filename,extract_dir,format shutil.unpack_archive
632
641
633
642
.. warning ::
@@ -640,18 +649,24 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
640
649
.. versionchanged :: 3.7
641
650
Accepts a :term: `path-like object ` for *filename * and *extract_dir *.
642
651
652
+ .. versionchanged :: 3.9.17
653
+ Added the *filter * argument.
654
+
643
655
.. function :: register_unpack_format(name, extensions, function[, extra_args[, description]])
644
656
645
657
Registers an unpack format. *name * is the name of the format and
646
658
*extensions * is a list of extensions corresponding to the format, like
647
659
``.zip `` for Zip files.
648
660
649
661
*function * is the callable that will be used to unpack archives. The
650
- callable will receive the path of the archive, followed by the directory
651
- the archive must be extracted to.
652
-
653
- When provided, *extra_args * is a sequence of ``(name, value) `` tuples that
654
- will be passed as keywords arguments to the callable.
662
+ callable will receive:
663
+
664
+ - the path of the archive, as a positional argument;
665
+ - the directory the archive must be extracted to, as a positional argument;
666
+ - possibly a *filter * keyword argument, if it was given to
667
+ :func: `unpack_archive `;
668
+ - additional keyword arguments, specified by *extra_args * as a sequence
669
+ of ``(name, value) `` tuples.
655
670
656
671
*description * can be provided to describe the format, and will be returned
657
672
by the :func: `get_unpack_formats ` function.
0 commit comments