File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import os
44import fnmatch
5+ import regex
56
67
78def glob (pathname ):
8- if not has_magic (pathname ): return [pathname ]
9+ if not has_magic (pathname ):
10+ if os .path .exists (pathname ):
11+ return [pathname ]
12+ else :
13+ return []
914 dirname , basename = os .path .split (pathname )
1015 if has_magic (dirname ):
1116 list = glob (dirname )
@@ -34,9 +39,13 @@ def glob1(dirname, pattern):
3439 return []
3540 result = []
3641 for name in names :
37- if name [0 ] <> '.' or pattern [0 ] == '.' :
38- if fnmatch .fnmatch (name , pattern ): result .append (name )
42+ if name [0 ] != '.' or pattern [0 ] == '.' :
43+ if fnmatch .fnmatch (name , pattern ):
44+ result .append (name )
3945 return result
4046
47+
48+ magic_check = regex .compile ('[*?[]' )
49+
4150def has_magic (s ):
42- return '*' in s or '?' in s or '[' in s
51+ return magic_check . search ( s ) >= 0
You can’t perform that action at this time.
0 commit comments