Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4f76fb1

Browse files
Issue #29210: Removed support of deprecated argument "exclude" in
tarfile.TarFile.add().
1 parent 62db0db commit 4f76fb1

5 files changed

Lines changed: 11 additions & 49 deletions

File tree

Doc/library/tarfile.rst

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -429,16 +429,13 @@ be finalized; only the internally used file object will be closed. See the
429429
Return an :class:`io.BufferedReader` object.
430430

431431

432-
.. method:: TarFile.add(name, arcname=None, recursive=True, exclude=None, *, filter=None)
432+
.. method:: TarFile.add(name, arcname=None, recursive=True, *, filter=None)
433433

434434
Add the file *name* to the archive. *name* may be any type of file
435435
(directory, fifo, symbolic link, etc.). If given, *arcname* specifies an
436436
alternative name for the file in the archive. Directories are added
437437
recursively by default. This can be avoided by setting *recursive* to
438-
:const:`False`. If *exclude* is given, it must be a function that takes one
439-
filename argument and returns a boolean value. Depending on this value the
440-
respective file is either excluded (:const:`True`) or added
441-
(:const:`False`). If *filter* is specified it must be a keyword argument. It
438+
:const:`False`. If *filter* is given, it
442439
should be a function that takes a :class:`TarInfo` object argument and
443440
returns the changed :class:`TarInfo` object. If it instead returns
444441
:const:`None` the :class:`TarInfo` object will be excluded from the
@@ -447,10 +444,6 @@ be finalized; only the internally used file object will be closed. See the
447444
.. versionchanged:: 3.2
448445
Added the *filter* parameter.
449446

450-
.. deprecated:: 3.2
451-
The *exclude* parameter is deprecated, please use the *filter* parameter
452-
instead.
453-
454447

455448
.. method:: TarFile.addfile(tarinfo, fileobj=None)
456449

Doc/whatsnew/3.7.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ API and Feature Removals
139139
* Unknown escapes consisting of ``'\'`` and an ASCII letter in replacement
140140
templates for :func:`re.sub` will now cause an error.
141141

142+
* Removed support of the *exclude* argument in :meth:`tarfile.TarFile.add`.
143+
Use the *filter* argument instead.
144+
142145

143146
Porting to Python 3.7
144147
=====================

Lib/tarfile.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,13 +1897,12 @@ def list(self, verbose=True, *, members=None):
18971897
_safe_print("link to " + tarinfo.linkname)
18981898
print()
18991899

1900-
def add(self, name, arcname=None, recursive=True, exclude=None, *, filter=None):
1900+
def add(self, name, arcname=None, recursive=True, *, filter=None):
19011901
"""Add the file `name' to the archive. `name' may be any type of file
19021902
(directory, fifo, symbolic link, etc.). If given, `arcname'
19031903
specifies an alternative name for the file in the archive.
19041904
Directories are added recursively by default. This can be avoided by
1905-
setting `recursive' to False. `exclude' is a function that should
1906-
return True for each filename to be excluded. `filter' is a function
1905+
setting `recursive' to False. `filter' is a function
19071906
that expects a TarInfo object argument and returns the changed
19081907
TarInfo object, if it returns None the TarInfo object will be
19091908
excluded from the archive.
@@ -1913,15 +1912,6 @@ def add(self, name, arcname=None, recursive=True, exclude=None, *, filter=None):
19131912
if arcname is None:
19141913
arcname = name
19151914

1916-
# Exclude pathnames.
1917-
if exclude is not None:
1918-
import warnings
1919-
warnings.warn("use the filter argument instead",
1920-
DeprecationWarning, 2)
1921-
if exclude(name):
1922-
self._dbg(2, "tarfile: Excluded %r" % name)
1923-
return
1924-
19251915
# Skip if somebody tries to archive the archive...
19261916
if self.name is not None and os.path.abspath(name) == self.name:
19271917
self._dbg(2, "tarfile: Skipped %r" % name)
@@ -1953,7 +1943,7 @@ def add(self, name, arcname=None, recursive=True, exclude=None, *, filter=None):
19531943
if recursive:
19541944
for f in os.listdir(name):
19551945
self.add(os.path.join(name, f), os.path.join(arcname, f),
1956-
recursive, exclude, filter=filter)
1946+
recursive, filter=filter)
19571947

19581948
else:
19591949
self.addfile(tarinfo)

Lib/test/test_tarfile.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,33 +1145,6 @@ def test_add_self(self):
11451145
finally:
11461146
tar.close()
11471147

1148-
def test_exclude(self):
1149-
tempdir = os.path.join(TEMPDIR, "exclude")
1150-
os.mkdir(tempdir)
1151-
try:
1152-
for name in ("foo", "bar", "baz"):
1153-
name = os.path.join(tempdir, name)
1154-
support.create_empty_file(name)
1155-
1156-
exclude = os.path.isfile
1157-
1158-
tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
1159-
try:
1160-
with support.check_warnings(("use the filter argument",
1161-
DeprecationWarning)):
1162-
tar.add(tempdir, arcname="empty_dir", exclude=exclude)
1163-
finally:
1164-
tar.close()
1165-
1166-
tar = tarfile.open(tmpname, "r")
1167-
try:
1168-
self.assertEqual(len(tar.getmembers()), 1)
1169-
self.assertEqual(tar.getnames()[0], "empty_dir")
1170-
finally:
1171-
tar.close()
1172-
finally:
1173-
support.rmtree(tempdir)
1174-
11751148
def test_filter(self):
11761149
tempdir = os.path.join(TEMPDIR, "filter")
11771150
os.mkdir(tempdir)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ Core and Builtins
212212
Library
213213
-------
214214

215+
- Issue #29210: Removed support of deprecated argument "exclude" in
216+
tarfile.TarFile.add().
217+
215218
- Issue #29219: Fixed infinite recursion in the repr of uninitialized
216219
ctypes.CDLL instances.
217220

0 commit comments

Comments
 (0)