File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,6 +37,26 @@ def fnmatch(name, pat):
3737 pat = os .path .normcase (pat )
3838 return fnmatchcase (name , pat )
3939
40+ def filter (names , pat ):
41+ """Return the subset of the list NAMES that match PAT"""
42+ import os ,posixpath
43+ result = []
44+ pat = os .path .normcase (pat )
45+ if not _cache .has_key (pat ):
46+ res = translate (pat )
47+ _cache [pat ] = re .compile (res )
48+ match = _cache [pat ].match
49+ if os .path is posixpath :
50+ # normcase on posix is NOP. Optimize it away from the loop.
51+ for name in names :
52+ if match (name ):
53+ result .append (name )
54+ else :
55+ for name in names :
56+ if match (os .path .normcase (name )):
57+ result .append (name )
58+ return result
59+
4060def fnmatchcase (name , pat ):
4161 """Test whether FILENAME matches PATTERN, including case.
4262
Original file line number Diff line number Diff line change @@ -18,7 +18,9 @@ def glob(pathname):
1818 else :
1919 return []
2020 dirname , basename = os .path .split (pathname )
21- if has_magic (dirname ):
21+ if not dirname :
22+ return glob1 (os .curdir , basename )
23+ elif has_magic (dirname ):
2224 list = glob (dirname )
2325 else :
2426 list = [dirname ]
@@ -43,12 +45,9 @@ def glob1(dirname, pattern):
4345 names = os .listdir (dirname )
4446 except os .error :
4547 return []
46- result = []
47- for name in names :
48- if name [0 ] != '.' or pattern [0 ] == '.' :
49- if fnmatch .fnmatch (name , pattern ):
50- result .append (name )
51- return result
48+ if pattern [0 ]!= '.' :
49+ names = filter (lambda x : x [0 ]!= '.' ,names )
50+ return fnmatch .filter (names ,pattern )
5251
5352
5453magic_check = re .compile ('[*?[]' )
You can’t perform that action at this time.
0 commit comments