@@ -352,12 +352,6 @@ def scandir(path):
352
352
"""
353
353
raise NotImplementedError
354
354
355
- @staticmethod
356
- def add_slash (path ):
357
- """Returns a path with a trailing slash added.
358
- """
359
- raise NotImplementedError
360
-
361
355
@staticmethod
362
356
def concat_path (path , text ):
363
357
"""Implements path concatenation.
@@ -389,10 +383,12 @@ def selector(self, parts):
389
383
def special_selector (self , part , parts ):
390
384
"""Returns a function that selects special children of the given path.
391
385
"""
386
+ if parts :
387
+ part += self .sep
392
388
select_next = self .selector (parts )
393
389
394
390
def select_special (path , exists = False ):
395
- path = self .concat_path (self . add_slash ( path ) , part )
391
+ path = self .concat_path (path , part )
396
392
return select_next (path , exists )
397
393
return select_special
398
394
@@ -402,14 +398,16 @@ def literal_selector(self, part, parts):
402
398
403
399
# Optimization: consume and join any subsequent literal parts here,
404
400
# rather than leaving them for the next selector. This reduces the
405
- # number of string concatenation operations and calls to add_slash() .
401
+ # number of string concatenation operations.
406
402
while parts and magic_check .search (parts [- 1 ]) is None :
407
403
part += self .sep + parts .pop ()
404
+ if parts :
405
+ part += self .sep
408
406
409
407
select_next = self .selector (parts )
410
408
411
409
def select_literal (path , exists = False ):
412
- path = self .concat_path (self . add_slash ( path ) , part )
410
+ path = self .concat_path (path , part )
413
411
return select_next (path , exists = False )
414
412
return select_literal
415
413
@@ -437,7 +435,7 @@ def select_wildcard(path, exists=False):
437
435
continue
438
436
except OSError :
439
437
continue
440
- if dir_only :
438
+ entry_path = self . concat_path ( entry_path , self . sep )
441
439
yield from select_next (entry_path , exists = True )
442
440
else :
443
441
yield entry_path
@@ -467,7 +465,6 @@ def recursive_selector(self, part, parts):
467
465
select_next = self .selector (parts )
468
466
469
467
def select_recursive (path , exists = False ):
470
- path = self .add_slash (path )
471
468
match_pos = len (str (path ))
472
469
if match is None or match (str (path ), match_pos ):
473
470
yield from select_next (path , exists )
@@ -491,7 +488,10 @@ def select_recursive_step(stack, match_pos):
491
488
pass
492
489
493
490
if is_dir or not dir_only :
494
- if match is None or match (str (entry_path ), match_pos ):
491
+ entry_path_str = str (entry_path )
492
+ if dir_only :
493
+ entry_path = self .concat_path (entry_path , self .sep )
494
+ if match is None or match (entry_path_str , match_pos ):
495
495
if dir_only :
496
496
yield from select_next (entry_path , exists = True )
497
497
else :
@@ -528,27 +528,12 @@ def scandir(path):
528
528
entries = list (scandir_it )
529
529
return ((entry , entry .name , entry .path ) for entry in entries )
530
530
531
- if os .name == 'nt' :
532
- @staticmethod
533
- def add_slash (pathname ):
534
- tail = os .path .splitroot (pathname )[2 ]
535
- if not tail or tail [- 1 ] in '\\ /' :
536
- return pathname
537
- return f'{ pathname } \\ '
538
- else :
539
- @staticmethod
540
- def add_slash (pathname ):
541
- if not pathname or pathname [- 1 ] == '/' :
542
- return pathname
543
- return f'{ pathname } /'
544
-
545
531
546
532
class _PathGlobber (_GlobberBase ):
547
533
"""Provides shell-style pattern matching and globbing for pathlib paths.
548
534
"""
549
535
550
536
lexists = operator .methodcaller ('exists' , follow_symlinks = False )
551
- add_slash = operator .methodcaller ('joinpath' , '' )
552
537
553
538
@staticmethod
554
539
def scandir (path ):
0 commit comments