33
33
from os import sendfile
34
34
except ImportError :
35
35
try :
36
- from sendfile import sendfile
36
+ from sendfile import sendfile # type: ignore
37
37
except ImportError :
38
38
sendfile = None
39
39
@@ -116,7 +116,7 @@ def __init__(
116
116
root_path = fsdecode (root_path )
117
117
self .root_path = root_path
118
118
_drive , _root_path = os .path .splitdrive (fsdecode (fspath (root_path )))
119
- _root_path = _drive + (_root_path or '/' ) if _drive else _root_path
119
+ _root_path = _drive + (_root_path or "/" ) if _drive else _root_path
120
120
_root_path = os .path .expanduser (os .path .expandvars (_root_path ))
121
121
_root_path = os .path .normpath (os .path .abspath (_root_path ))
122
122
self ._root_path = _root_path
@@ -378,7 +378,6 @@ def opendir(self, path, factory=None):
378
378
# type: (_O, Text, Optional[_OpendirFactory]) -> SubFS[_O]
379
379
pass
380
380
381
-
382
381
# --- Backport of os.sendfile for Python < 3.8 -----------
383
382
384
383
def _check_copy (self , src_path , dst_path , overwrite = False ):
@@ -396,31 +395,35 @@ def _check_copy(self, src_path, dst_path, overwrite=False):
396
395
raise errors .DirectoryExpected (dirname (dst_path ))
397
396
return _src_path , _dst_path
398
397
399
-
400
398
if sys .version_info [:2 ] < (3 , 8 ) and sendfile is not None :
401
399
402
- _sendfile_error_codes = frozenset ({
403
- errno .EIO ,
404
- errno .EINVAL ,
405
- errno .ENOSYS ,
406
- errno .ENOTSUP ,
407
- errno .EBADF ,
408
- errno .ENOTSOCK ,
409
- errno .EOPNOTSUPP ,
410
- })
400
+ _sendfile_error_codes = frozenset (
401
+ {
402
+ errno .EIO ,
403
+ errno .EINVAL ,
404
+ errno .ENOSYS ,
405
+ errno .ENOTSUP , # type: ignore
406
+ errno .EBADF ,
407
+ errno .ENOTSOCK ,
408
+ errno .EOPNOTSUPP ,
409
+ }
410
+ )
411
411
412
412
def copy (self , src_path , dst_path , overwrite = False ):
413
413
# type: (Text, Text, bool) -> None
414
414
with self ._lock :
415
415
# validate and canonicalise paths
416
416
_src_path , _dst_path = self ._check_copy (src_path , dst_path , overwrite )
417
- _src_sys , _dst_sys = self .getsyspath (_src_path ), self .getsyspath (_dst_path )
417
+ _src_sys , _dst_sys = (
418
+ self .getsyspath (_src_path ),
419
+ self .getsyspath (_dst_path ),
420
+ )
418
421
# attempt using sendfile
419
422
try :
420
423
# initialise variables to pass to sendfile
421
424
# open files to obtain a file descriptor
422
- with io .open (_src_sys , 'r' ) as src :
423
- with io .open (_dst_sys , 'w' ) as dst :
425
+ with io .open (_src_sys , "r" ) as src :
426
+ with io .open (_dst_sys , "w" ) as dst :
424
427
fd_src , fd_dst = src .fileno (), dst .fileno ()
425
428
sent = maxsize = os .fstat (fd_src ).st_size
426
429
offset = 0
0 commit comments