1 """Filename globbing utility."""
10 """Return a list of paths matching a pathname pattern.
12 The pattern may contain simple shell-style wildcards a la fnmatch.
15 if not has_magic(pathname
):
16 if os
.path
.exists(pathname
):
20 dirname
, basename
= os
.path
.split(pathname
)
21 if has_magic(dirname
):
25 if not has_magic(basename
):
28 if basename
or os
.path
.isdir(dirname
):
29 name
= os
.path
.join(dirname
, basename
)
30 if os
.path
.exists(name
):
35 sublist
= glob1(dirname
, basename
)
37 result
.append(os
.path
.join(dirname
, name
))
40 def glob1(dirname
, pattern
):
41 if not dirname
: dirname
= os
.curdir
43 names
= os
.listdir(dirname
)
48 if name
[0] != '.' or pattern
[0] == '.':
49 if fnmatch
.fnmatch(name
, pattern
):
54 magic_check
= re
.compile('[*?[]')
57 return magic_check
.search(s
) is not None