@@ -64,16 +64,23 @@ def _is_wildcard_pattern(pat):
64
64
# Globbing helpers
65
65
#
66
66
67
+
68
+ _SWAP_SLASH_AND_NEWLINE = str .maketrans ({'/' : '\n ' , '\n ' : '/' })
69
+
70
+
67
71
@functools .lru_cache ()
68
72
def _make_matcher (path_cls , pattern , recursive ):
69
73
pattern = path_cls (pattern )
70
74
if not pattern ._parts :
71
75
raise ValueError ("empty pattern" )
72
76
result = [r'\A' if pattern ._drv or pattern ._root else '^' ]
73
8000
- for line in pattern ._lines_normcase :
77
+ for line in pattern ._lines_normcase . splitlines ( keepends = True ) :
74
78
if recursive :
75
79
if line == '**\n ' :
76
- result .append ('(.*\n )*' )
80
+ result .append (r'[\S\s]*^' )
81
+ continue
82
+ elif line == '**' :
83
+ result .append (r'[\S\s]*' )
77
84
continue
78
85
elif '**' in line :
79
86
raise ValueError ("Invalid pattern: '**' can only be an entire path component" )
@@ -659,14 +666,16 @@ def is_reserved(self):
659
666
660
667
@property
661
668
def _lines_normcase (self ):
662
- return [f'{ part } \n ' for part in self ._parts_normcase ]
669
+ path = self ._flavour .normcase (self .as_posix ())
670
+ return path .translate (_SWAP_SLASH_AND_NEWLINE )
663
671
664
672
def match (self , path_pattern , recursive = False ):
665
673
"""
666
674
Return True if this path matches the given pattern.
667
675
"""
668
676
matcher = _make_matcher (type (self ), path_pattern , recursive )
669
- return matcher .search ('' .join (self ._lines_normcase )) is not None
677
+ return matcher .search (self ._lines_normcase ) is not None
678
+
670
679
671
680
# Can't subclass os.PathLike from PurePath and keep the constructor
672
681
# optimizations in PurePath._parse_args().
0 commit comments