registered for that extension. In case none is found,
a :exc:`ValueError` is raised.
+ .. versionchanged:: 3.7
+ Accepts a :term:`path-like object` for *filename* and *extract_dir*.
+
.. function:: register_unpack_format(name, extensions, function[, extra_args[, description]])
import os.path
import errno
import functools
+import pathlib
import subprocess
from shutil import (make_archive,
register_archive_format, unregister_archive_format,
self.assertNotIn('xxx', formats)
def check_unpack_archive(self, format):
+ self.check_unpack_archive_with_converter(format, lambda path: path)
+ self.check_unpack_archive_with_converter(format, pathlib.Path)
+
+ class MyPath:
+ def __init__(self, path):
+ self.path = path
+ def __fspath__(self):
+ return self.path
+
+ self.check_unpack_archive_with_converter(format, MyPath)
+
+ def check_unpack_archive_with_converter(self, format, converter):
root_dir, base_dir = self._create_files()
expected = rlistdir(root_dir)
expected.remove('outer')
# let's try to unpack it now
tmpdir2 = self.mkdtemp()
- unpack_archive(filename, tmpdir2)
+ unpack_archive(converter(filename), converter(tmpdir2))
self.assertEqual(rlistdir(tmpdir2), expected)
# and again, this time with the format specified
tmpdir3 = self.mkdtemp()
- unpack_archive(filename, tmpdir3, format=format)
+ unpack_archive(converter(filename), converter(tmpdir3), format=format)
self.assertEqual(rlistdir(tmpdir3), expected)
- self.assertRaises(shutil.ReadError, unpack_archive, TESTFN)
- self.assertRaises(ValueError, unpack_archive, TESTFN, format='xxx')
+ self.assertRaises(shutil.ReadError, unpack_archive, converter(TESTFN))
+ self.assertRaises(ValueError, unpack_archive, converter(TESTFN), format='xxx')
def test_unpack_archive_tar(self):
self.check_unpack_archive('tar')
Fixed possible other errors caused by not checking results of PyObject_Size(),
PySequence_Size(), or PyMapping_Size().
+- bpo-30218: Fix PathLike support for shutil.unpack_archive. Patch by Jelle
+ Zijlstra.
+
- bpo-10076: Compiled regular expression and match objects in the re module
now support copy.copy() and copy.deepcopy() (they are considered atomic).