mirror of
https://github.com/python/cpython.git
synced 2026-05-06 20:51:17 -04:00
gh-81325: Support path-like objects with streaming TarFile (#137188)
Co-authored-by: Emma Smith <emma@emmatyping.dev>
This commit is contained in:
committed by
GitHub
parent
b266fbc9ec
commit
3ec3d05345
+1
-1
@@ -353,7 +353,7 @@ class _Stream:
|
||||
fileobj = _StreamProxy(fileobj)
|
||||
comptype = fileobj.getcomptype()
|
||||
|
||||
self.name = name or ""
|
||||
self.name = os.fspath(name) if name is not None else ""
|
||||
self.mode = mode
|
||||
self.comptype = comptype
|
||||
self.fileobj = fileobj
|
||||
|
||||
@@ -1737,6 +1737,16 @@ class StreamWriteTest(WriteTestBase, unittest.TestCase):
|
||||
finally:
|
||||
os.umask(original_umask)
|
||||
|
||||
def test_pathlike_name(self):
|
||||
expected_name = os.path.abspath(tmpname)
|
||||
tarpath = os_helper.FakePath(tmpname)
|
||||
|
||||
for func in (tarfile.open, tarfile.TarFile.open):
|
||||
with self.subTest():
|
||||
with func(tarpath, self.mode) as tar:
|
||||
self.assertEqual(tar.name, expected_name)
|
||||
os_helper.unlink(tmpname)
|
||||
|
||||
|
||||
class GzipStreamWriteTest(GzipTest, StreamWriteTest):
|
||||
def test_source_directory_not_leaked(self):
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
:class:`tarfile.TarFile` now accepts a :term:`path-like <path-like object>` when working on a tar archive.
|
||||
(Contributed by Alexander Enrique Urieles Nieto in :gh:`81325`.)
|
||||
Reference in New Issue
Block a user