diff -r 08042f0dbb67 Doc/library/tarfile.rst --- a/Doc/library/tarfile.rst Sun Jan 08 23:30:05 2017 +0800 +++ b/Doc/library/tarfile.rst Sun Jan 08 20:21:37 2017 +0200 @@ -429,16 +429,13 @@ be finalized; only the internally used f Return an :class:`io.BufferedReader` object. -.. method:: TarFile.add(name, arcname=None, recursive=True, exclude=None, *, filter=None) +.. method:: TarFile.add(name, arcname=None, recursive=True, *, filter=None) Add the file *name* to the archive. *name* may be any type of file (directory, fifo, symbolic link, etc.). If given, *arcname* specifies an alternative name for the file in the archive. Directories are added recursively by default. This can be avoided by setting *recursive* to - :const:`False`. If *exclude* is given, it must be a function that takes one - filename argument and returns a boolean value. Depending on this value the - respective file is either excluded (:const:`True`) or added - (:const:`False`). If *filter* is specified it must be a keyword argument. It + :const:`False`. If *filter* is specified it must be a keyword argument. It should be a function that takes a :class:`TarInfo` object argument and returns the changed :class:`TarInfo` object. If it instead returns :const:`None` the :class:`TarInfo` object will be excluded from the @@ -447,10 +444,6 @@ be finalized; only the internally used f .. versionchanged:: 3.2 Added the *filter* parameter. - .. deprecated:: 3.2 - The *exclude* parameter is deprecated, please use the *filter* parameter - instead. - .. method:: TarFile.addfile(tarinfo, fileobj=None) diff -r 08042f0dbb67 Doc/whatsnew/3.7.rst --- a/Doc/whatsnew/3.7.rst Sun Jan 08 23:30:05 2017 +0800 +++ b/Doc/whatsnew/3.7.rst Sun Jan 08 20:21:37 2017 +0200 @@ -132,6 +132,9 @@ API and Feature Removals * Unknown escapes consisting of ``'\'`` and an ASCII letter in replacement templates for :func:`re.sub` will now cause an error. +* Removed the support of the *exclude* argument in :meth:`tarfile.TarFile.add`. + Use the *filter* argument instead. + Porting to Python 3.7 ===================== diff -r 08042f0dbb67 Lib/tarfile.py --- a/Lib/tarfile.py Sun Jan 08 23:30:05 2017 +0800 +++ b/Lib/tarfile.py Sun Jan 08 20:21:37 2017 +0200 @@ -1897,13 +1897,12 @@ class TarFile(object): _safe_print("link to " + tarinfo.linkname) print() - def add(self, name, arcname=None, recursive=True, exclude=None, *, filter=None): + def add(self, name, arcname=None, recursive=True, *, filter=None): """Add the file `name' to the archive. `name' may be any type of file (directory, fifo, symbolic link, etc.). If given, `arcname' specifies an alternative name for the file in the archive. Directories are added recursively by default. This can be avoided by - setting `recursive' to False. `exclude' is a function that should - return True for each filename to be excluded. `filter' is a function + setting `recursive' to False. `filter' is a function that expects a TarInfo object argument and returns the changed TarInfo object, if it returns None the TarInfo object will be excluded from the archive. @@ -1913,15 +1912,6 @@ class TarFile(object): if arcname is None: arcname = name - # Exclude pathnames. - if exclude is not None: - import warnings - warnings.warn("use the filter argument instead", - DeprecationWarning, 2) - if exclude(name): - self._dbg(2, "tarfile: Excluded %r" % name) - return - # Skip if somebody tries to archive the archive... if self.name is not None and os.path.abspath(name) == self.name: self._dbg(2, "tarfile: Skipped %r" % name) @@ -1953,7 +1943,7 @@ class TarFile(object): if recursive: for f in os.listdir(name): self.add(os.path.join(name, f), os.path.join(arcname, f), - recursive, exclude, filter=filter) + recursive, filter=filter) else: self.addfile(tarinfo) diff -r 08042f0dbb67 Lib/test/test_tarfile.py --- a/Lib/test/test_tarfile.py Sun Jan 08 23:30:05 2017 +0800 +++ b/Lib/test/test_tarfile.py Sun Jan 08 20:21:37 2017 +0200 @@ -1145,33 +1145,6 @@ class WriteTest(WriteTestBase, unittest. finally: tar.close() - def test_exclude(self): - tempdir = os.path.join(TEMPDIR, "exclude") - os.mkdir(tempdir) - try: - for name in ("foo", "bar", "baz"): - name = os.path.join(tempdir, name) - support.create_empty_file(name) - - exclude = os.path.isfile - - tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1") - try: - with support.check_warnings(("use the filter argument", - DeprecationWarning)): - tar.add(tempdir, arcname="empty_dir", exclude=exclude) - finally: - tar.close() - - tar = tarfile.open(tmpname, "r") - try: - self.assertEqual(len(tar.getmembers()), 1) - self.assertEqual(tar.getnames()[0], "empty_dir") - finally: - tar.close() - finally: - support.rmtree(tempdir) - def test_filter(self): tempdir = os.path.join(TEMPDIR, "filter") os.mkdir(tempdir)