shutil: copyfileobj(): Support file objects without readinto() method.

pull/20/merge
Paul Sokolovsky 2015-02-04 02:50:04 +02:00
rodzic 94b2afdf8b
commit f3dd9abcda
1 zmienionych plików z 16 dodań i 9 usunięć

Wyświetl plik

@ -9,6 +9,7 @@ def rmtree(top):
os.rmdir(path)
def copyfileobj(src, dest, length=512):
if hasattr(src, "readinto"):
buf = bytearray(length)
while True:
sz = src.readinto(buf)
@ -19,3 +20,9 @@ def copyfileobj(src, dest, length=512):
else:
b = memoryview(buf)[:sz]
dest.write(b)
else:
while True:
buf = src.read(length)
if not buf:
break
dest.write(buf)