Skip to content
Snippets Groups Projects
Commit d815cc066df8 authored by Inada Naoki's avatar Inada Naoki
Browse files

bpo-43787: Add __iter__ to GzipFile, BZ2File, and LZMAFile (GH-25353)

parent e72ec941c76f
Branches
No related tags found
No related merge requests found
...@@ -197,6 +197,10 @@ ...@@ -197,6 +197,10 @@
self._check_can_read() self._check_can_read()
return self._buffer.readline(size) return self._buffer.readline(size)
def __iter__(self):
self._check_can_read()
return self._buffer.__iter__()
def readlines(self, size=-1): def readlines(self, size=-1):
"""Read a list of lines of uncompressed bytes from the file. """Read a list of lines of uncompressed bytes from the file.
......
...@@ -398,6 +398,10 @@ ...@@ -398,6 +398,10 @@
self._check_not_closed() self._check_not_closed()
return self._buffer.readline(size) return self._buffer.readline(size)
def __iter__(self):
self._check_not_closed()
return self._buffer.__iter__()
class _GzipReader(_compression.DecompressReader): class _GzipReader(_compression.DecompressReader):
def __init__(self, fp): def __init__(self, fp):
......
...@@ -221,6 +221,10 @@ ...@@ -221,6 +221,10 @@
self._check_can_read() self._check_can_read()
return self._buffer.readline(size) return self._buffer.readline(size)
def __iter__(self):
self._check_can_read()
return self._buffer.__iter__()
def write(self, data): def write(self, data):
"""Write a bytes object to the file. """Write a bytes object to the file.
......
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.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment