Skip to content

Commit ff33f99

Browse files
committed
add mode checks for _MemoryFile readline and readlines methods
1 parent f04ec4e commit ff33f99

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

fs/memoryfs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ def next(self):
120120

121121
def readline(self, size=-1):
122122
# type: (int) -> bytes
123+
if not self._mode.reading:
124+
raise IOError("File not open for reading")
123125
with self._seek_lock():
124126
self.on_access()
125127
return self._bytes_io.readline(size)
@@ -153,6 +155,8 @@ def readinto(self, b):
153155

154156
def readlines(self, hint=-1):
155157
# type: (int) -> List[bytes]
158+
if not self._mode.reading:
159+
raise IOError("File not open for reading")
156160
with self._seek_lock():
157161
self.on_access()
158162
return self._bytes_io.readlines(hint)

0 commit comments

Comments
 (0)