@@ -401,15 +401,14 @@ def select_from(self, parent_path):
401
401
path_cls = type (parent_path )
402
402
is_dir = path_cls .is_dir
403
403
exists = path_cls .exists
404
- scandir = parent_path ._accessor .scandir
405
404
if not is_dir (parent_path ):
406
405
return iter ([])
407
- return self ._select_from (parent_path , is_dir , exists , scandir )
406
+ return self ._select_from (parent_path , is_dir , exists )
408
407
409
408
410
409
class _TerminatingSelector :
411
410
412
- def _select_from (self , parent_path , is_dir , exists , scandir ):
411
+ def _select_from (self , parent_path , is_dir , exists ):
413
412
yield parent_path
414
413
415
414
@@ -419,11 +418,11 @@ def __init__(self, name, child_parts, flavour):
419
418
self .name = name
420
419
_Selector .__init__ (self , child_parts , flavour )
421
420
422
- def _select_from (self , parent_path , is_dir , exists , scandir ):
421
+ def _select_from (self , parent_path , is_dir , exists ):
423
422
try :
424
423
path = parent_path ._make_child_relpath (self .name )
425
424
if (is_dir if self .dironly else exists )(path ):
426
- for p in self .successor ._select_from (path , is_dir , exists , scandir ):
425
+ for p in self .successor ._select_from (path , is_dir , exists ):
427
426
yield p
428
427
except PermissionError :
429
428
return
@@ -435,9 +434,9 @@ def __init__(self, pat, child_parts, flavour):
435
434
self .match = flavour .compile_pattern (pat )
436
435
_Selector .__init__ (self , child_parts , flavour )
437
436
438
- def _select_from (self , parent_path , is_dir , exists , scandir ):
437
+ def _select_from (self , parent_path , is_dir , exists ):
439
438
try :
440
- with scandir (parent_path ) as scandir_it :
439
+ with parent_path . scandir () as scandir_it :
441
440
entries = list (scandir_it )
442
441
for entry in entries :
443
442
if self .dironly :
@@ -454,7 +453,7 @@ def _select_from(self, parent_path, is_dir, exists, scandir):
454
453
name = entry .name
455
454
if self .match (name ):
456
455
path = parent_path ._make_child_relpath (name )
457
- for p in self .successor ._select_from (path , is_dir , exists , scandir ):
456
+ for p in self .successor ._select_from (path , is_dir , exists ):
458
457
yield p
459
458
except PermissionError :
460
459
return
@@ -465,10 +464,10 @@ class _RecursiveWildcardSelector(_Selector):
465
464
def __init__ (self , pat , child_parts , flavour ):
466
465
_Selector .__init__ (self , child_parts , flavour )
467
466
468
- def _iterate_directories (self , parent_path , is_dir , scandir ):
467
+ def _iterate_directories (self , parent_path , is_dir ):
469
468
yield parent_path
470
469
try :
471
- with scandir (parent_path ) as scandir_it :
470
+ with parent_path . scandir () as scandir_it :
472
471
entries = list (scandir_it )
473
472
for entry in entries :
474
473
entry_is_dir = False
@@ -479,18 +478,18 @@ def _iterate_directories(self, parent_path, is_dir, scandir):
479
478
raise
480
479
if entry_is_dir and not entry .is_symlink ():
481
480
path = parent_path ._make_child_relpath (entry .name )
482
- for p in self ._iterate_directories (path , is_dir , scandir ):
481
+ for p in self ._iterate_directories (path , is_dir ):
483
482
yield p
484
483
except PermissionError :
485
484
return
486
485
487
- def _select_from (self , parent_path , is_dir , exists , scandir ):
486
+ def _select_from (self , parent_path , is_dir , exists ):
488
487
try :
489
488
yielded = set ()
490
489
try :
491
490
successor_select = self .successor ._select_from
492
- for starting_point in self ._iterate_directories (parent_path , is_dir , scandir ):
493
- for p in successor_select (starting_point , is_dir , exists , scandir ):
491
+ for starting_point in self ._iterate_directories (parent_path , is_dir ):
492
+ for p in successor_select (starting_point , is_dir , exists ):
494
493
if p not in yielded :
495
494
yield p
496
495
yielded .add (p )
@@ -1018,6 +1017,9 @@ def iterdir(self):
1018
1017
continue
1019
1018
yield self ._make_child_relpath (name )
1020
1019
1020
+ def scandir (self ):
1021
+ return self ._accessor .scandir (self )
1022
+
1021
1023
def glob (self , pattern ):
1022
1024
"""Iterate over this subtree and yield all existing files (of any
1023
1025
kind, including directories) matching the given relative pattern.
0 commit comments