Skip to content

Commit a11a198

Browse files
committed
Adjust the docs for 3.7.17
1 parent fc9913d commit a11a198

File tree

3 files changed

+52
-43
lines changed

3 files changed

+52
-43
lines changed

Doc/library/shutil.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,9 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
553553
registered for that extension. In case none is found,
554554
a :exc:`ValueError` is raised.
555555

556-
The keyword-only *filter* argument is passed to the underlying unpacking
557-
function. For zip files, *filter* is not accepted.
556+
The keyword-only *filter* argument, which was added in Python 3.7.17,
557+
is passed to the underlying unpacking function.
558+
For zip files, *filter* is not accepted.
558559
For tar files, it is recommended to set it to ``'data'``,
559560
unless using features specific to tar and UNIX-like filesystems.
560561
(See :ref:`tarfile-extraction-filter` for details.)
@@ -564,7 +565,7 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
564565
.. versionchanged:: 3.7
565566
Accepts a :term:`path-like object` for *filename* and *extract_dir*.
566567

567-
.. versionchanged:: 3.8.17
568+
.. versionchanged:: 3.7.17
568569
Added the *filter* argument.
569570

570571
.. function:: register_unpack_format(name, extensions, function[, extra_args[, description]])

Doc/library/tarfile.rst

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ Some facts and figures:
3636
.. versionchanged:: 3.3
3737
Added support for :mod:`lzma` compression.
3838

39-
.. versionchanged:: 3.12
40-
Archives are extracted using a :ref:`filter <tarfile-extraction-filter>`,
41-
which makes it possible to either limit surprising/dangerous features,
42-
or to acknowledge that they are expected and the archive is fully trusted.
43-
By default, archives are fully trusted, but this default is deprecated
44-
and slated to change in Python 3.14.
45-
4639

4740
.. function:: open(name=None, mode='r', fileobj=None, bufsize=10240, \*\*kwargs)
4841

@@ -425,8 +418,8 @@ be finalized; only the internally used file object will be closed. See the
425418
are used to set the owner/group for the extracted files. Otherwise, the named
426419
values from the tarfile are used.
427420

428-
The *filter* argument specifies how ``members`` are modified or rejected
429-
before extraction.
421+
The *filter* argument, which was added in Python 3.7.17, specifies how
422+
``members`` are modified or rejected before extraction.
430423
See :ref:`tarfile-extraction-filter` for details.
431424
It is recommended to set this explicitly depending on which *tar* features
432425
you need to support.
@@ -447,7 +440,7 @@ be finalized; only the internally used file object will be closed. See the
447440
.. versionchanged:: 3.6
448441
The *path* parameter accepts a :term:`path-like object`.
449442

450-
.. versionchanged:: 3.12
443+
.. versionchanged:: 3.7.17
451444
Added the *filter* parameter.
452445

453446

@@ -483,7 +476,7 @@ be finalized; only the internally used file object will be closed. See the
483476
.. versionchanged:: 3.6
484477
The *path* parameter accepts a :term:`path-like object`.
485478

486-
.. versionchanged:: 3.12
479+
.. versionchanged:: 3.7.17
487480
Added the *filter* parameter.
488481

489482

@@ -498,7 +491,6 @@ be finalized; only the internally used file object will be closed. See the
498491
Return an :class:`io.BufferedReader` object.
499492

500493
.. attribute:: TarFile.errorlevel
501-
:type: int
502494

503495
If *errorlevel* is ``0``, errors are ignored when using :meth:`TarFile.extract`
504496
and :meth:`TarFile.extractall`.
@@ -520,7 +512,7 @@ be finalized; only the internally used file object will be closed. See the
520512

521513
.. attribute:: TarFile.extraction_filter
522514

523-
.. versionadded:: 3.12
515+
.. versionadded:: 3.7.17
524516

525517
The :ref:`extraction filter <tarfile-extraction-filter>` used
526518
as a default for the *filter* argument of :meth:`~TarFile.extract`
@@ -531,10 +523,12 @@ be finalized; only the internally used file object will be closed. See the
531523
argument to :meth:`~TarFile.extract`.
532524

533525
If ``extraction_filter`` is ``None`` (the default),
534-
calling an extraction method without a *filter* argument will raise a
535-
``DeprecationWarning``,
536-
and fall back to the :func:`fully_trusted <fully_trusted_filter>` filter,
537-
whose dangerous behavior matches previous versions of Python.
526+
calling an extraction method without a *filter* argument will
527+
use the :func:`fully_trusted <fully_trusted_filter>` filter for
528+
compatibility with previous Python versions.
529+
530+
In Python 3.12+, leaving ``extraction_filter=None`` will emit a
531+
``DeprecationWarning``.
538532

539533
In Python 3.14+, leaving ``extraction_filter=None`` will cause
540534
extraction methods to use the :func:`data <data_filter>` filter by default.
@@ -639,6 +633,11 @@ Different :class:`TarInfo` methods handle ``None`` differently:
639633
- :meth:`~TarFile.addfile` will fail.
640634
- :meth:`~TarFile.list` will print a placeholder string.
641635

636+
637+
.. versionchanged:: 3.7.17
638+
Added :meth:`~TarInfo.replace` and handling of ``None``.
639+
640+
642641
.. class:: TarInfo(name="")
643642

644643
Create a :class:`TarInfo` object.
@@ -670,35 +669,31 @@ A ``TarInfo`` object has the following public data attributes:
670669

671670

672671
.. attribute:: TarInfo.name
673-
:type: str
674672

675673
Name of the archive member.
676674

677675

678676
.. attribute:: TarInfo.size
679-
:type: int
680677

681678
Size in bytes.
682679

683680

684681
.. attribute:: TarInfo.mtime
685-
:type: int | float
686682

687683
Time of last modification in seconds since the :ref:`epoch <epoch>`,
688684
as in :attr:`os.stat_result.st_mtime`.
689685

690-
.. versionchanged:: 3.12
686+
.. versionchanged:: 3.7.17
691687

692688
Can be set to ``None`` for :meth:`~TarFile.extract` and
693689
:meth:`~TarFile.extractall`, causing extraction to skip applying this
694690
attribute.
695691

696692
.. attribute:: TarInfo.mode
697-
:type: int
698693

699694
Permission bits, as for :func:`os.chmod`.
700695

701-
.. versionchanged:: 3.12
696+
.. versionchanged:: 3.7.17
702697

703698
Can be set to ``None`` for :meth:`~TarFile.extract` and
704699
:meth:`~TarFile.extractall`, causing extraction to skip applying this
@@ -714,66 +709,60 @@ A ``TarInfo`` object has the following public data attributes:
714709

715710

716711
.. attribute:: TarInfo.linkname
717-
:type: str
718712

719713
Name of the target file name, which is only present in :class:`TarInfo` objects
720714
of type :const:`LNKTYPE` and :const:`SYMTYPE`.
721715

722716

723717
.. attribute:: TarInfo.uid
724-
:type: int
725718

726719
User ID of the user who originally stored this member.
727720

728-
.. versionchanged:: 3.12
721+
.. versionchanged:: 3.7.17
729722

730723
Can be set to ``None`` for :meth:`~TarFile.extract` and
731724
:meth:`~TarFile.extractall`, causing extraction to skip applying this
732725
attribute.
733726

734727
.. attribute:: TarInfo.gid
735-
:type: int
736728

737729
Group ID of the user who originally stored this member.
738730

739-
.. versionchanged:: 3.12
731+
.. versionchanged:: 3.7.17
740732

741733
Can be set to ``None`` for :meth:`~TarFile.extract` and
742734
:meth:`~TarFile.extractall`, causing extraction to skip applying this
743735
attribute.
744736

745737
.. attribute:: TarInfo.uname
746-
:type: str
747738

748739
User name.
749740

750-
.. versionchanged:: 3.12
741+
.. versionchanged:: 3.7.17
751742

752743
Can be set to ``None`` for :meth:`~TarFile.extract` and
753744
:meth:`~TarFile.extractall`, causing extraction to skip applying this
754745
attribute.
755746

756747
.. attribute:: TarInfo.gname
757-
:type: str
758748

759749
Group name.
760750

761-
.. versionchanged:: 3.12
751+
.. versionchanged:: 3.7.17
762752

763753
Can be set to ``None`` for :meth:`~TarFile.extract` and
764754
:meth:`~TarFile.extractall`, causing extraction to skip applying this
765755
attribute.
766756

767757
.. attribute:: TarInfo.pax_headers
768-
:type: dict
769758

770759
A dictionary containing key-value pairs of an associated pax extended header.
771760

772761
.. method:: TarInfo.replace(name=..., mtime=..., mode=..., linkname=...,
773762
uid=..., gid=..., uname=..., gname=...,
774763
deep=True)
775764

776-
.. versionadded:: 3.12
765+
.. versionadded:: 3.7.17
777766

778767
Return a *new* copy of the :class:`!TarInfo` object with the given attributes
779768
changed. For example, to return a ``TarInfo`` with the group name set to
@@ -838,7 +827,7 @@ A :class:`TarInfo` object also provides some convenient query methods:
838827
Extraction filters
839828
------------------
840829

841-
.. versionadded:: 3.12
830+
.. versionadded:: 3.7.17
842831

843832
The *tar* format is designed to capture all details of a UNIX-like filesystem,
844833
which makes it very powerful.
@@ -875,9 +864,10 @@ can be:
875864

876865
* ``None`` (default): Use :attr:`TarFile.extraction_filter`.
877866

878-
If that is also ``None`` (the default), raise a ``DeprecationWarning``,
879-
and fall back to the ``'fully_trusted'`` filter, whose dangerous behavior
880-
matches previous versions of Python.
867+
If that is also ``None`` (the default), the ``'fully_trusted'``
868+
filter will be used (for compatibility with earlier versions of Python).
869+
870+
In Python 3.12, the default will emit a ``DeprecationWarning``.
881871

882872
In Python 3.14, the ``'data'`` filter will become the default instead.
883873
It's possible to switch earlier; see :attr:`TarFile.extraction_filter`.
@@ -1014,7 +1004,7 @@ Also note that:
10141004
Supporting older Python versions
10151005
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10161006

1017-
Extraction filters were added to Python 3.12, but may be backported to older
1007+
Extraction filters were added to Python 3.12, and are backported to older
10181008
versions as security updates.
10191009
To check whether the feature is available, use e.g.
10201010
``hasattr(tarfile, 'data_filter')`` rather than checking the Python version.
@@ -1161,6 +1151,8 @@ Command-line options
11611151
Only string names are accepted (that is, ``fully_trusted``, ``tar``,
11621152
and ``data``).
11631153

1154+
.. versionadded:: 3.7.17
1155+
11641156
.. _tar-examples:
11651157

11661158
Examples
@@ -1170,7 +1162,7 @@ How to extract an entire tar archive to the current working directory::
11701162

11711163
import tarfile
11721164
tar = tarfile.open("sample.tar.gz")
1173-
tar.extractall(filter='data')
1165+
tar.extractall()
11741166
tar.close()
11751167

11761168
How to extract a subset of a tar archive with :meth:`TarFile.extractall` using

Doc/whatsnew/3.7.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2615,3 +2615,19 @@ This limit can be configured or disabled by environment variable, command
26152615
line flag, or :mod:`sys` APIs. See the :ref:`integer string conversion
26162616
length limitation <int_max_str_digits>` documentation. The default limit
26172617
is 4300 digits in string form.
2618+
2619+
Notable Changes in 3.7.17
2620+
=========================
2621+
2622+
tarfile
2623+
-------
2624+
2625+
* The extraction methods in :mod:`tarfile`, and :func:`shutil.unpack_archive`,
2626+
have a new a *filter* argument that allows limiting tar features than may be
2627+
surprising or dangerous, such as creating files outside the destination
2628+
directory.
2629+
See :ref:`tarfile-extraction-filter` for details.
2630+
In Python 3.12, use without the *filter* argument will show a
2631+
:exc:`DeprecationWarning`.
2632+
In Python 3.14, the default will switch to ``'data'``.
2633+
(Contributed by Petr Viktorin in :pep:`706`.)

0 commit comments

Comments
 (0)