mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
bpo-43787: Add __iter__ to GzipFile, BZ2File, and LZMAFile (GH-25353)
This commit is contained in:
parent
d9151cb453
commit
d2a8e69c2c
4 changed files with 15 additions and 0 deletions
|
@ -197,6 +197,10 @@ class BZ2File(_compression.BaseStream):
|
|||
self._check_can_read()
|
||||
return self._buffer.readline(size)
|
||||
|
||||
def __iter__(self):
|
||||
self._check_can_read()
|
||||
return self._buffer.__iter__()
|
||||
|
||||
def readlines(self, size=-1):
|
||||
"""Read a list of lines of uncompressed bytes from the file.
|
||||
|
||||
|
|
|
@ -398,6 +398,10 @@ class GzipFile(_compression.BaseStream):
|
|||
self._check_not_closed()
|
||||
return self._buffer.readline(size)
|
||||
|
||||
def __iter__(self):
|
||||
self._check_not_closed()
|
||||
return self._buffer.__iter__()
|
||||
|
||||
|
||||
class _GzipReader(_compression.DecompressReader):
|
||||
def __init__(self, fp):
|
||||
|
|
|
@ -221,6 +221,10 @@ class LZMAFile(_compression.BaseStream):
|
|||
self._check_can_read()
|
||||
return self._buffer.readline(size)
|
||||
|
||||
def __iter__(self):
|
||||
self._check_can_read()
|
||||
return self._buffer.__iter__()
|
||||
|
||||
def write(self, data):
|
||||
"""Write a bytes object to the file.
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
Add ``__iter__()`` method to :class:`bz2.BZ2File`, :class:`gzip.GzipFile`, and
|
||||
:class:`lzma.LZMAFile`. It makes iterating them about 2x faster. Patch by
|
||||
Inada Naoki.
|
Loading…
Add table
Add a link
Reference in a new issue