Skip to content

Commit 221b9e5

Browse files
committed
Rewrite buffering in FTPFile.writelines to work with more argument types
1 parent 5a27e2e commit 221b9e5

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

fs/ftpfs.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,15 @@ def write(self, data):
290290

291291
def writelines(self, lines):
292292
# type: (Iterable[Union[bytes, bytearray, memoryview, array.array[Any], mmap.mmap]]) -> None
293+
if not self.mode.writing:
294+
raise IOError("File not open for writing")
295+
data = bytearray()
293296
for line in lines:
294-
self.write(line)
297+
if isinstance(line, array.array):
298+
data.extend(line.tobytes())
299+
else:
300+
data.extend(line) # type: ignore
301+
self.write(data)
295302

296303
def truncate(self, size=None):
297304
# type: (Optional[int]) -> int

0 commit comments

Comments
 (0)