11import argparse
22import fnmatch
3- import os . path
3+ import posixpath
44import re
55import sys
66import unicodedata
@@ -142,7 +142,7 @@ def match(self, path):
142142 in self.fallback is returned (defaults to None).
143143
144144 """
145- path = normalize_path (path ).lstrip (os . path . sep )
145+ path = normalize_path (path ).lstrip ("/" )
146146 # do a fast lookup for full path matches (note: we do not count such matches):
147147 non_existent = object ()
148148 value = self ._path_full_patterns .get (path , non_existent )
@@ -215,7 +215,7 @@ class PathFullPattern(PatternBase):
215215 PREFIX = "pf"
216216
217217 def _prepare (self , pattern ):
218- self .pattern = os . path . normpath (pattern ).lstrip (os . path . sep ) # sep at beginning is removed
218+ self .pattern = posixpath . normpath (pattern ).lstrip ("/" ) # / at beginning is removed
219219
220220 def _match (self , path ):
221221 return path == self .pattern
@@ -236,12 +236,10 @@ class PathPrefixPattern(PatternBase):
236236 PREFIX = "pp"
237237
238238 def _prepare (self , pattern ):
239- sep = os .path .sep
240-
241- self .pattern = (os .path .normpath (pattern ).rstrip (sep ) + sep ).lstrip (sep ) # sep at beginning is removed
239+ self .pattern = (posixpath .normpath (pattern ).rstrip ("/" ) + "/" ).lstrip ("/" ) # / at beginning is removed
242240
243241 def _match (self , path ):
244- return (path + os . path . sep ).startswith (self .pattern )
242+ return (path + "/" ).startswith (self .pattern )
245243
246244
247245class FnmatchPattern (PatternBase ):
@@ -252,19 +250,19 @@ class FnmatchPattern(PatternBase):
252250 PREFIX = "fm"
253251
254252 def _prepare (self , pattern ):
255- if pattern .endswith (os . path . sep ):
256- pattern = os . path . normpath (pattern ).rstrip (os . path . sep ) + os . path . sep + "*" + os . path . sep
253+ if pattern .endswith ("/" ):
254+ pattern = posixpath . normpath (pattern ).rstrip ("/" ) + "/*/"
257255 else :
258- pattern = os . path . normpath (pattern ) + os . path . sep + " *"
256+ pattern = posixpath . normpath (pattern ) + "/ *"
259257
260- self .pattern = pattern .lstrip (os . path . sep ) # sep at beginning is removed
258+ self .pattern = pattern .lstrip ("/" ) # / at beginning is removed
261259
262260 # fnmatch and re.match both cache compiled regular expressions.
263261 # Nevertheless, this is about 10 times faster.
264262 self .regex = re .compile (fnmatch .translate (self .pattern ))
265263
266264 def _match (self , path ):
267- return self .regex .match (path + os . path . sep ) is not None
265+ return self .regex .match (path + "/" ) is not None
268266
269267
270268class ShellPattern (PatternBase ):
@@ -275,18 +273,16 @@ class ShellPattern(PatternBase):
275273 PREFIX = "sh"
276274
277275 def _prepare (self , pattern ):
278- sep = os .path .sep
279-
280- if pattern .endswith (sep ):
281- pattern = os .path .normpath (pattern ).rstrip (sep ) + sep + "**" + sep + "*" + sep
276+ if pattern .endswith ("/" ):
277+ pattern = posixpath .normpath (pattern ).rstrip ("/" ) + "/**/*/"
282278 else :
283- pattern = os . path . normpath (pattern ) + sep + "**" + sep + " *"
279+ pattern = posixpath . normpath (pattern ) + "/**/ *"
284280
285- self .pattern = pattern .lstrip (sep ) # sep at beginning is removed
281+ self .pattern = pattern .lstrip ("/" ) # / at beginning is removed
286282 self .regex = re .compile (shellpattern .translate (self .pattern ))
287283
288284 def _match (self , path ):
289- return self .regex .match (path + os . path . sep ) is not None
285+ return self .regex .match (path + "/" ) is not None
290286
291287
292288class RegexPattern (PatternBase ):
@@ -295,14 +291,11 @@ class RegexPattern(PatternBase):
295291 PREFIX = "re"
296292
297293 def _prepare (self , pattern ):
298- self .pattern = pattern # sep at beginning is NOT removed
294+ self .pattern = pattern # / at beginning is NOT removed
299295 self .regex = re .compile (pattern )
300296
301297 def _match (self , path ):
302- # Normalize path separators
303- if os .path .sep != "/" :
304- path = path .replace (os .path .sep , "/" )
305-
298+ assert "\\ " not in path
306299 return self .regex .search (path ) is not None
307300
308301
0 commit comments