gh-115961: Add name and mode attributes for compressed file-like objects (GH-116036)

* Add name and mode attributes for compressed and archived file-like objects
  in modules bz2, lzma, tarfile and zipfile.
* Change the value of the mode attribute of GzipFile from integer (1 or 2)
  to string ('rb' or 'wb').
* Change the value of the mode attribute of ZipExtFile from 'r' to 'rb'.
This commit is contained in:
Serhiy Storchaka 2024-04-21 11:46:39 +03:00 committed by GitHub
parent ccda738284
commit 51ef89cd9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 246 additions and 37 deletions

View file

@ -587,6 +587,8 @@ class TestGzip(BaseTest):
self.assertRaises(AttributeError, f.fileno)
def test_fileobj_mode(self):
self.assertEqual(gzip.READ, 'rb')
self.assertEqual(gzip.WRITE, 'wb')
gzip.GzipFile(self.filename, "wb").close()
with open(self.filename, "r+b") as f:
with gzip.GzipFile(fileobj=f, mode='r') as g: