@@ -73,8 +73,13 @@ class RegistryError(Exception):
73
73
and unpacking registries fails"""
74
74
75
75
76
- def copyfileobj (fsrc , fdst , length = 16 * 1024 ):
77
- """copy data from file-like object fsrc to file-like object fdst"""
76
+ def copyfileobj (fsrc , fdst , length = None ):
77
+ """Copy data from file-like object `fsrc` to file-like object `fdst`.
78
+
79
+ An in-memory buffer size can be set with `length`; the default is 16 KB.
80
+ """
81
+ if not length :
82
+ length = 16 * 1024
78
83
while 1 :
79
84
buf = fsrc .read (length )
80
85
if not buf :
@@ -93,12 +98,14 @@ def _samefile(src, dst):
93
98
return (os .path .normcase (os .path .abspath (src )) ==
94
99
os .path .normcase (os .path .abspath (dst )))
95
100
96
- def copyfile (src , dst , * , follow_symlinks = True ):
101
+ def copyfile (src , dst , * , follow_symlinks = True , length = None ):
97
102
"""Copy data from src to dst.
98
103
99
104
If follow_symlinks is not set and src is a symbolic link, a new
100
105
symlink will be created instead of copying the file it points to.
101
106
107
+ An in memory buffer size can be set with `length`; the default is 16 kB.
108
+
102
109
"""
103
110
if _samefile (src , dst ):
104
111
raise SameFileError ("{!r} and {!r} are the same file" .format (src , dst ))
@@ -119,7 +126,7 @@ def copyfile(src, dst, *, follow_symlinks=True):
119
126
else :
120
127
with open (src , 'rb' ) as fsrc :
121
128
with open (dst , 'wb' ) as fdst :
122
- copyfileobj (fsrc , fdst )
129
+ copyfileobj (fsrc , fdst , length = length )
123
130
return dst
124
131
125
132
def copymode (src , dst , * , follow_symlinks = True ):
@@ -224,7 +231,7 @@ def lookup(name):
224
231
raise
225
232
_copyxattr (src , dst , follow_symlinks = follow )
226
233
227
- def copy (src , dst , * , follow_symlinks = True ):
234
+ def copy (src , dst , * , follow_symlinks = True , length = None ):
228
235
"""Copy data and mode bits ("cp src dst"). Return the file's destination.
229
236
230
237
The destination may be a directory.
@@ -238,11 +245,11 @@ def copy(src, dst, *, follow_symlinks=True):
238
245
"""
239
246
if os .path .isdir (dst ):
240
247
dst = os .path .join (dst , os .path .basename (src ))
241
- copyfile (src , dst , follow_symlinks = follow_symlinks )
248
+ copyfile (src , dst , follow_symlinks = follow_symlinks , length = length )
242
249
copymode (src , dst , follow_symlinks = follow_symlinks )
243
250
return dst
244
251
245
- def copy2 (src , dst , * , follow_symlinks = True ):
252
+ def copy2 (src , dst , * , follow_symlinks = True , length = None ):
246
253
"""Copy data and all stat info ("cp -p src dst"). Return the file's
247
254
destination."
248
255
@@ -254,7 +261,7 @@ def copy2(src, dst, *, follow_symlinks=True):
254
261
"""
255
262
if os .path .isdir (dst ):
256
263
dst = os .path .join (dst , os .path .basename (src ))
257
- copyfile (src , dst , follow_symlinks = follow_symlinks )
264
+ copyfile (src , dst , follow_symlinks = follow_symlinks , length = length )
258
265
copystat (src , dst , follow_symlinks = follow_symlinks )
259
266
return dst
260
267
0 commit comments