File Doc/library/shutil.rst changed (mode: 100644) (index 41e5bafa53..2b84fa2937) |
... |
... |
provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules. |
550 |
550 |
registered for that extension. In case none is found, |
registered for that extension. In case none is found, |
551 |
551 |
a :exc:`ValueError` is raised. |
a :exc:`ValueError` is raised. |
552 |
552 |
|
|
|
553 |
|
.. versionchanged:: 3.7 |
|
554 |
|
Accepts a :term:`path-like object` for *filename* and *extract_dir*. |
|
555 |
|
|
553 |
556 |
|
|
554 |
557 |
.. function:: register_unpack_format(name, extensions, function[, extra_args[, description]]) |
.. function:: register_unpack_format(name, extensions, function[, extra_args[, description]]) |
555 |
558 |
|
|
File Lib/test/test_shutil.py changed (mode: 100644) (index c7f7d1d3e6..f21e6adf4a) |
... |
... |
import os |
10 |
10 |
import os.path |
import os.path |
11 |
11 |
import errno |
import errno |
12 |
12 |
import functools |
import functools |
|
13 |
|
import pathlib |
13 |
14 |
import subprocess |
import subprocess |
14 |
15 |
from shutil import (make_archive, |
from shutil import (make_archive, |
15 |
16 |
register_archive_format, unregister_archive_format, |
register_archive_format, unregister_archive_format, |
|
... |
... |
class TestShutil(unittest.TestCase): |
1223 |
1224 |
self.assertNotIn('xxx', formats) |
self.assertNotIn('xxx', formats) |
1224 |
1225 |
|
|
1225 |
1226 |
def check_unpack_archive(self, format): |
def check_unpack_archive(self, format): |
|
1227 |
|
self.check_unpack_archive_with_converter(format, lambda path: path) |
|
1228 |
|
self.check_unpack_archive_with_converter(format, pathlib.Path) |
|
1229 |
|
|
|
1230 |
|
class MyPath: |
|
1231 |
|
def __init__(self, path): |
|
1232 |
|
self.path = path |
|
1233 |
|
def __fspath__(self): |
|
1234 |
|
return self.path |
|
1235 |
|
|
|
1236 |
|
self.check_unpack_archive_with_converter(format, MyPath) |
|
1237 |
|
|
|
1238 |
|
def check_unpack_archive_with_converter(self, format, converter): |
1226 |
1239 |
root_dir, base_dir = self._create_files() |
root_dir, base_dir = self._create_files() |
1227 |
1240 |
expected = rlistdir(root_dir) |
expected = rlistdir(root_dir) |
1228 |
1241 |
expected.remove('outer') |
expected.remove('outer') |
|
... |
... |
class TestShutil(unittest.TestCase): |
1232 |
1245 |
|
|
1233 |
1246 |
# let's try to unpack it now |
# let's try to unpack it now |
1234 |
1247 |
tmpdir2 = self.mkdtemp() |
tmpdir2 = self.mkdtemp() |
1235 |
|
unpack_archive(filename, tmpdir2) |
|
|
1248 |
|
unpack_archive(converter(filename), converter(tmpdir2)) |
1236 |
1249 |
self.assertEqual(rlistdir(tmpdir2), expected) |
self.assertEqual(rlistdir(tmpdir2), expected) |
1237 |
1250 |
|
|
1238 |
1251 |
# and again, this time with the format specified |
# and again, this time with the format specified |
1239 |
1252 |
tmpdir3 = self.mkdtemp() |
tmpdir3 = self.mkdtemp() |
1240 |
|
unpack_archive(filename, tmpdir3, format=format) |
|
|
1253 |
|
unpack_archive(converter(filename), converter(tmpdir3), format=format) |
1241 |
1254 |
self.assertEqual(rlistdir(tmpdir3), expected) |
self.assertEqual(rlistdir(tmpdir3), expected) |
1242 |
1255 |
|
|
1243 |
|
self.assertRaises(shutil.ReadError, unpack_archive, TESTFN) |
|
1244 |
|
self.assertRaises(ValueError, unpack_archive, TESTFN, format='xxx') |
|
|
1256 |
|
self.assertRaises(shutil.ReadError, unpack_archive, converter(TESTFN)) |
|
1257 |
|
self.assertRaises(ValueError, unpack_archive, converter(TESTFN), format='xxx') |
1245 |
1258 |
|
|
1246 |
1259 |
def test_unpack_archive_tar(self): |
def test_unpack_archive_tar(self): |
1247 |
1260 |
self.check_unpack_archive('tar') |
self.check_unpack_archive('tar') |
File Misc/NEWS changed (mode: 100644) (index 25619efddf..0c403cb0cf) |
... |
... |
Library |
362 |
362 |
Fixed possible other errors caused by not checking results of PyObject_Size(), |
Fixed possible other errors caused by not checking results of PyObject_Size(), |
363 |
363 |
PySequence_Size(), or PyMapping_Size(). |
PySequence_Size(), or PyMapping_Size(). |
364 |
364 |
|
|
|
365 |
|
- bpo-30218: Fix PathLike support for shutil.unpack_archive. Patch by Jelle |
|
366 |
|
Zijlstra. |
|
367 |
|
|
365 |
368 |
- bpo-10076: Compiled regular expression and match objects in the re module |
- bpo-10076: Compiled regular expression and match objects in the re module |
366 |
369 |
now support copy.copy() and copy.deepcopy() (they are considered atomic). |
now support copy.copy() and copy.deepcopy() (they are considered atomic). |
367 |
370 |
|
|