@@ -36,13 +36,6 @@ Some facts and figures:
36
36
.. versionchanged :: 3.3
37
37
Added support for :mod: `lzma ` compression.
38
38
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
-
46
39
47
40
.. function :: open(name=None, mode='r', fileobj=None, bufsize=10240, **kwargs)
48
41
@@ -437,8 +430,8 @@ be finalized; only the internally used file object will be closed. See the
437
430
are used to set the owner/group for the extracted files. Otherwise, the named
438
431
values from the tarfile are used.
439
432
440
- The *filter * argument specifies how `` members `` are modified or rejected
441
- before extraction.
433
+ The *filter * argument, which was added in Python 3.11.4, specifies how
434
+ `` members `` are modified or rejected before extraction.
442
435
See :ref: `tarfile-extraction-filter ` for details.
443
436
It is recommended to set this explicitly depending on which *tar * features
444
437
you need to support.
@@ -459,7 +452,7 @@ be finalized; only the internally used file object will be closed. See the
459
452
.. versionchanged :: 3.6
460
453
The *path * parameter accepts a :term: `path-like object `.
461
454
462
- .. versionchanged :: 3.12
455
+ .. versionchanged :: 3.11.4
463
456
Added the *filter * parameter.
464
457
465
458
@@ -495,7 +488,7 @@ be finalized; only the internally used file object will be closed. See the
495
488
.. versionchanged :: 3.6
496
489
The *path * parameter accepts a :term: `path-like object `.
497
490
498
- .. versionchanged :: 3.12
491
+ .. versionchanged :: 3.11.4
499
492
Added the *filter * parameter.
500
493
501
494
@@ -533,7 +526,7 @@ be finalized; only the internally used file object will be closed. See the
533
526
534
527
.. attribute :: TarFile.extraction_filter
535
528
536
- .. versionadded :: 3.12
529
+ .. versionadded :: 3.11.4
537
530
538
531
The :ref: `extraction filter <tarfile-extraction-filter >` used
539
532
as a default for the *filter * argument of :meth: `~TarFile.extract `
@@ -544,10 +537,12 @@ be finalized; only the internally used file object will be closed. See the
544
537
argument to :meth: `~TarFile.extract `.
545
538
546
539
If ``extraction_filter `` is ``None `` (the default),
547
- calling an extraction method without a *filter * argument will raise a
548
- ``DeprecationWarning ``,
549
- and fall back to the :func: `fully_trusted <fully_trusted_filter> ` filter,
550
- whose dangerous behavior matches previous versions of Python.
540
+ calling an extraction method without a *filter * argument will
541
+ use the :func: `fully_trusted <fully_trusted_filter> ` filter for
542
+ compatibility with previous Python versions.
543
+
544
+ In Python 3.12+, leaving ``extraction_filter=None `` will emit a
545
+ ``DeprecationWarning ``.
551
546
552
547
In Python 3.14+, leaving ``extraction_filter=None `` will cause
553
548
extraction methods to use the :func: `data <data_filter> ` filter by default.
@@ -652,6 +647,11 @@ Different :class:`TarInfo` methods handle ``None`` differently:
652
647
- :meth: `~TarFile.addfile ` will fail.
653
648
- :meth: `~TarFile.list ` will print a placeholder string.
654
649
650
+
651
+ .. versionchanged :: 3.11.4
652
+ Added :meth: `~TarInfo.replace ` and handling of ``None ``.
653
+
654
+
655
655
.. class :: TarInfo(name="")
656
656
657
657
Create a :class: `TarInfo ` object.
@@ -700,7 +700,7 @@ A ``TarInfo`` object has the following public data attributes:
700
700
Time of last modification in seconds since the :ref: `epoch <epoch >`,
701
701
as in :attr: `os.stat_result.st_mtime `.
702
702
703
- .. versionchanged :: 3.12
703
+ .. versionchanged :: 3.11.4
704
704
705
705
Can be set to ``None `` for :meth: `~TarFile.extract ` and
706
706
:meth: `~TarFile.extractall `, causing extraction to skip applying this
@@ -711,7 +711,7 @@ A ``TarInfo`` object has the following public data attributes:
711
711
712
712
Permission bits, as for :func: `os.chmod `.
713
713
714
- .. versionchanged :: 3.12
714
+ .. versionchanged :: 3.11.4
715
715
716
716
Can be set to ``None `` for :meth: `~TarFile.extract ` and
717
717
:meth: `~TarFile.extractall `, causing extraction to skip applying this
@@ -738,7 +738,7 @@ A ``TarInfo`` object has the following public data attributes:
738
738
739
739
User ID of the user who originally stored this member.
740
740
741
- .. versionchanged :: 3.12
741
+ .. versionchanged :: 3.11.4
742
742
743
743
Can be set to ``None `` for :meth: `~TarFile.extract ` and
744
744
:meth: `~TarFile.extractall `, causing extraction to skip applying this
@@ -749,7 +749,7 @@ A ``TarInfo`` object has the following public data attributes:
749
749
750
750
Group ID of the user who originally stored this member.
751
751
752
- .. versionchanged :: 3.12
752
+ .. versionchanged :: 3.11.4
753
753
754
754
Can be set to ``None `` for :meth: `~TarFile.extract ` and
755
755
:meth: `~TarFile.extractall `, causing extraction to skip applying this
@@ -760,7 +760,7 @@ A ``TarInfo`` object has the following public data attributes:
760
760
761
761
User name.
762
762
763
- .. versionchanged :: 3.12
763
+ .. versionchanged :: 3.11.4
764
764
765
765
Can be set to ``None `` for :meth: `~TarFile.extract ` and
766
766
:meth: `~TarFile.extractall `, causing extraction to skip applying this
@@ -771,7 +771,7 @@ A ``TarInfo`` object has the following public data attributes:
771
771
772
772
Group name.
773
773
774
- .. versionchanged :: 3.12
774
+ .. versionchanged :: 3.11.4
775
775
776
776
Can be set to ``None `` for :meth: `~TarFile.extract ` and
777
777
:meth: `~TarFile.extractall `, causing extraction to skip applying this
@@ -786,7 +786,7 @@ A ``TarInfo`` object has the following public data attributes:
786
786
uid=..., gid=..., uname=..., gname=...,
787
787
deep=True)
788
788
789
- .. versionadded :: 3.12
789
+ .. versionadded :: 3.11.4
790
790
791
791
Return a *new * copy of the :class: `!TarInfo ` object with the given attributes
792
792
changed. For example, to return a ``TarInfo `` with the group name set to
@@ -851,7 +851,7 @@ A :class:`TarInfo` object also provides some convenient query methods:
851
851
Extraction filters
852
852
------------------
853
853
854
- .. versionadded :: 3.12
854
+ .. versionadded :: 3.11.4
855
855
856
856
The *tar * format is designed to capture all details of a UNIX-like filesystem,
857
857
which makes it very powerful.
@@ -888,9 +888,10 @@ can be:
888
888
889
889
* ``None `` (default): Use :attr: `TarFile.extraction_filter `.
890
890
891
- If that is also ``None `` (the default), raise a ``DeprecationWarning ``,
892
- and fall back to the ``'fully_trusted' `` filter, whose dangerous behavior
893
- matches previous versions of Python.
891
+ If that is also ``None `` (the default), the ``'fully_trusted' ``
892
+ filter will be used (for compatibility with earlier versions of Python).
893
+
894
+ In Python 3.12, the default will emit a ``DeprecationWarning ``.
894
895
895
896
In Python 3.14, the ``'data' `` filter will become the default instead.
896
897
It's possible to switch earlier; see :attr: `TarFile.extraction_filter `.
@@ -1027,7 +1028,7 @@ Also note that:
1027
1028
Supporting older Python versions
1028
1029
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1029
1030
1030
- Extraction filters were added to Python 3.12, but may be backported to older
1031
+ Extraction filters were added to Python 3.12, and are backported to older
1031
1032
versions as security updates.
1032
1033
To check whether the feature is available, use e.g.
1033
1034
``hasattr(tarfile, 'data_filter') `` rather than checking the Python version.
@@ -1174,6 +1175,8 @@ Command-line options
1174
1175
Only string names are accepted (that is, ``fully_trusted ``, ``tar ``,
1175
1176
and ``data ``).
1176
1177
1178
+ .. versionadded :: 3.11.4
1179
+
1177
1180
.. _tar-examples :
1178
1181
1179
1182
Examples
@@ -1183,7 +1186,7 @@ How to extract an entire tar archive to the current working directory::
1183
1186
1184
1187
import tarfile
1185
1188
tar = tarfile.open("sample.tar.gz")
1186
- tar.extractall(filter='data' )
1189
+ tar.extractall()
1187
1190
tar.close()
1188
1191
1189
1192
How to extract a subset of a tar archive with :meth: `TarFile.extractall ` using
0 commit comments