1 """Filename globbing utility."""
7 __all__ = ["glob", "iglob"]
10 """Return a list of paths matching a pathname pattern.
12 The pattern may contain simple shell-style wildcards a la fnmatch.
15 return list(iglob(pathname))
18 """Return a list of paths matching a pathname pattern.
20 The pattern may contain simple shell-style wildcards a la fnmatch.
23 if not has_magic(pathname):
24 if os.path.lexists(pathname):
27 dirname, basename = os.path.split(pathname)
29 for name in glob1(os.curdir, basename):
32 if has_magic(dirname):
36 if has_magic(basename):
41 for name in glob_in_dir(dirname, basename):
42 yield os.path.join(dirname, name)
44 # These 2 helper functions non-recursively glob inside a literal directory.
45 # They return a list of basenames. `glob1` accepts a pattern while `glob0`
46 # takes a literal basename (so it only has to check for its existence).
48 def glob1(dirname, pattern):
52 names = os.listdir(dirname)
56 names=filter(lambda x: x[0]!='.',names)
57 return fnmatch.filter(names,pattern)
59 def glob0(dirname, basename):
61 # `os.path.split()` returns an empty basename for paths ending with a
62 # directory separator. 'q*x/' should match only directories.
63 if os.path.isdir(dirname):
66 if os.path.lexists(os.path.join(dirname, basename)):
71 magic_check = re.compile('[*?[]')
74 return magic_check.search(s) is not None