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
)
22 return glob1(os
.curdir
, basename
)
23 elif has_magic(dirname
):
27 if not has_magic(basename
):
30 if basename
or os
.path
.isdir(dirname
):
31 name
= os
.path
.join(dirname
, basename
)
32 if os
.path
.exists(name
):
37 sublist
= glob1(dirname
, basename
)
39 result
.append(os
.path
.join(dirname
, name
))
42 def glob1(dirname
, pattern
):
43 if not dirname
: dirname
= os
.curdir
45 names
= os
.listdir(dirname
)
49 names
=filter(lambda x
: x
[0]!='.',names
)
50 return fnmatch
.filter(names
,pattern
)
53 magic_check
= re
.compile('[*?[]')
56 return magic_check
.search(s
) is not None