Skip to content

Commit 71055c5

Browse files
committed
add mode checks for _MemoryFile readline and readlines methods
1 parent eb5ae0e commit 71055c5

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
@@ -115,6 +115,8 @@ def next(self):
115115

116116
def readline(self, size=-1):
117117
# type: (int) -> bytes
118+
if not self._mode.reading:
119+
raise IOError("File not open for reading")
118120
with self._seek_lock():
119121
self.on_access()
120122
return self._bytes_io.readline(size)
@@ -148,6 +150,8 @@ def readinto(self, b):
148150

149151
def readlines(self, hint=-1):
150152
# type: (int) -> List[bytes]
153+
if not self._mode.reading:
154+
raise IOError("File not open for reading")
151155
with self._seek_lock():
152156
self.on_access()
153157
return self._bytes_io.readlines(hint)

0 commit comments

Comments
 (0)