@@ -662,7 +662,7 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
662
662
Remove the archive format *name * from the list of supported formats.
663
663
664
664
665
- .. function :: unpack_archive(filename[, extract_dir[, format]])
665
+ .. function :: unpack_archive(filename[, extract_dir[, format[, filter] ]])
666
666
667
667
Unpack an archive. *filename * is the full path of the archive.
668
668
@@ -676,6 +676,14 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
676
676
registered for that extension. In case none is found,
677
677
a :exc: `ValueError ` is raised.
678
678
679
+ The keyword-only *filter * argument is passed to the underlying unpacking
680
+ function. For zip files, *filter * is not accepted.
681
+ For tar files, it is recommended to set it to ``'data' ``,
682
+ unless using features specific to tar and UNIX-like filesystems.
683
+ (See :ref: `tarfile-extraction-filter ` for details.)
684
+ The ``'data' `` filter will become the default for tar files
685
+ in Python 3.14.
686
+
679
687
.. audit-event :: shutil.unpack_archive filename,extract_dir,format shutil.unpack_archive
680
688
681
689
.. warning ::
@@ -688,18 +696,24 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
688
696
.. versionchanged :: 3.7
689
697
Accepts a :term: `path-like object ` for *filename * and *extract_dir *.
690
698
699
+ .. versionchanged :: 3.12
700
+ Added the *filter * argument.
701
+
691
702
.. function :: register_unpack_format(name, extensions, function[, extra_args[, description]])
692
703
693
704
Registers an unpack format. *name * is the name of the format and
694
705
*extensions * is a list of extensions corresponding to the format, like
695
706
``.zip `` for Zip files.
696
707
697
708
*function * is the callable that will be used to unpack archives. The
698
- callable will receive the path of the archive, followed by the directory
699
- the archive must be extracted to.
700
-
701
- When provided, *extra_args * is a sequence of ``(name, value) `` tuples that
702
- will be passed as keywords arguments to the callable.
709
+ callable will receive:
710
+
711
+ - the path of the archive, as a positional argument;
712
+ - the directory the archive must be extracted to, as a positional argument;
713
+ - possibly a *filter * keyword argument, if it was given to
714
+ :func: `unpack_archive `;
715
+ - additional keyword arguments, specified by *extra_args * as a sequence
716
+ of ``(name, value) `` tuples.
703
717
704
718
*description * can be provided to describe the format, and will be returned
705
719
by the :func: `get_unpack_formats ` function.
0 commit comments