summaryrefslogtreecommitdiff
path: root/Doc/library/shutil.rst
diff options
context:
space:
mode:
authorPetr Viktorin <encukou@gmail.com>2023-05-17 14:23:56 +0200
committerGitHub <noreply@github.com>2023-05-17 14:23:56 +0200
commit79e63e528795c700a8bd198c15f3322ee25ea786 (patch)
tree307b133252bf5b617ccf761140e72ce86c31083e /Doc/library/shutil.rst
parent3205d1fbbbfcf613b74d236be9db7a8225f452ea (diff)
downloadcpython-git-3.8.tar.gz
[3.8] gh-102950: Implement PEP 706 – Filter for tarfile.extractall (GH-102953) (#104548)3.8
Backport of c8c3956d905e019101038b018129a4c90c9c9b8f
Diffstat (limited to 'Doc/library/shutil.rst')
-rw-r--r--Doc/library/shutil.rst33
1 files changed, 27 insertions, 6 deletions
diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst
index cd32a0a6e0..c424c823ef 100644
--- a/Doc/library/shutil.rst
+++ b/Doc/library/shutil.rst
@@ -640,7 +640,7 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
Remove the archive format *name* from the list of supported formats.
-.. function:: unpack_archive(filename[, extract_dir[, format]])
+.. function:: unpack_archive(filename[, extract_dir[, format[, filter]]])
Unpack an archive. *filename* is the full path of the archive.
@@ -654,11 +654,29 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
registered for that extension. In case none is found,
a :exc:`ValueError` is raised.
+ The keyword-only *filter* argument, which was added in Python 3.8.17,
+ is passed to the underlying unpacking function.
+ For zip files, *filter* is not accepted.
+ For tar files, it is recommended to set it to ``'data'``,
+ unless using features specific to tar and UNIX-like filesystems.
+ (See :ref:`tarfile-extraction-filter` for details.)
+ The ``'data'`` filter will become the default for tar files
+ in Python 3.14.
+
.. audit-event:: shutil.unpack_archive filename,extract_dir,format shutil.unpack_archive
+ .. warning::
+
+ Never extract archives from untrusted sources without prior inspection.
+ It is possible that files are created outside of the path specified in
+ the *extract_dir* argument, e.g. members that have absolute filenames
+ starting with "/" or filenames with two dots "..".
+
.. versionchanged:: 3.7
Accepts a :term:`path-like object` for *filename* and *extract_dir*.
+ .. versionchanged:: 3.8.17
+ Added the *filter* argument.
.. function:: register_unpack_format(name, extensions, function[, extra_args[, description]])
@@ -667,11 +685,14 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
``.zip`` for Zip files.
*function* is the callable that will be used to unpack archives. The
- callable will receive the path of the archive, followed by the directory
- the archive must be extracted to.
-
- When provided, *extra_args* is a sequence of ``(name, value)`` tuples that
- will be passed as keywords arguments to the callable.
+ callable will receive:
+
+ - the path of the archive, as a positional argument;
+ - the directory the archive must be extracted to, as a positional argument;
+ - possibly a *filter* keyword argument, if it was given to
+ :func:`unpack_archive`;
+ - additional keyword arguments, specified by *extra_args* as a sequence
+ of ``(name, value)`` tuples.
*description* can be provided to describe the format, and will be returned
by the :func:`get_unpack_formats` function.