summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorInada Naoki <songofacandy@gmail.com>2021-04-13 04:51:49 (GMT)
committerGitHub <noreply@github.com>2021-04-13 04:51:49 (GMT)
commitd2a8e69c2c605fbaa3656a5f99aa8d295f74c80e (patch)
tree1f9874eec667494b36e238bb416fb133450b0f64 /Lib
parentd9151cb45371836d39b6d53afb50c5bcd353c661 (diff)
downloadcpython-d2a8e69c2c605fbaa3656a5f99aa8d295f74c80e.zip
cpython-d2a8e69c2c605fbaa3656a5f99aa8d295f74c80e.tar.gz
cpython-d2a8e69c2c605fbaa3656a5f99aa8d295f74c80e.tar.bz2
bpo-43787: Add __iter__ to GzipFile, BZ2File, and LZMAFile (GH-25353)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/bz2.py4
-rw-r--r--Lib/gzip.py4
-rw-r--r--Lib/lzma.py4
3 files changed, 12 insertions, 0 deletions
diff --git a/Lib/bz2.py b/Lib/bz2.py
index 43f321a..a2c588e 100644
--- a/Lib/bz2.py
+++ b/Lib/bz2.py
@@ -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.
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 0a8993b..9a4e0f9 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -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):
diff --git a/Lib/lzma.py b/Lib/lzma.py
index c8b1970..2ada7d8 100644
--- a/Lib/lzma.py
+++ b/Lib/lzma.py
@@ -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.