Back to index

python3.2  3.2.2
Functions | Variables
glob Namespace Reference

Functions

def glob
def iglob
def glob1
def glob0
def has_magic

Variables

list __all__ = ["glob", "iglob"]
tuple magic_check = re.compile('[*?[]')
tuple magic_check_bytes = re.compile(b'[*?[]')

Detailed Description

Filename globbing utility.

Function Documentation

def glob.glob (   pathname)
Return a list of paths matching a pathname pattern.

The pattern may contain simple shell-style wildcards a la fnmatch.

Definition at line 9 of file glob.py.

00009 
00010 def glob(pathname):
00011     """Return a list of paths matching a pathname pattern.
00012 
00013     The pattern may contain simple shell-style wildcards a la fnmatch.
00014 
00015     """
00016     return list(iglob(pathname))

Here is the call graph for this function:

Here is the caller graph for this function:

def glob.glob0 (   dirname,
  basename 
)

Definition at line 62 of file glob.py.

00062 
00063 def glob0(dirname, basename):
00064     if basename == '':
00065         # `os.path.split()` returns an empty basename for paths ending with a
00066         # directory separator.  'q*x/' should match only directories.
00067         if os.path.isdir(dirname):
00068             return [basename]
00069     else:
00070         if os.path.lexists(os.path.join(dirname, basename)):
00071             return [basename]
00072     return []
00073 

def glob.glob1 (   dirname,
  pattern 
)

Definition at line 48 of file glob.py.

00048 
00049 def glob1(dirname, pattern):
00050     if not dirname:
00051         if isinstance(pattern, bytes):
00052             dirname = bytes(os.curdir, 'ASCII')
00053         else:
00054             dirname = os.curdir
00055     try:
00056         names = os.listdir(dirname)
00057     except os.error:
00058         return []
00059     if pattern[0] != '.':
00060         names = [x for x in names if x[0] != '.']
00061     return fnmatch.filter(names, pattern)

Here is the call graph for this function:

Here is the caller graph for this function:

def glob.has_magic (   s)

Definition at line 77 of file glob.py.

00077 
00078 def has_magic(s):
00079     if isinstance(s, bytes):
00080         match = magic_check_bytes.search(s)
00081     else:
00082         match = magic_check.search(s)
00083     return match is not None

Here is the caller graph for this function:

def glob.iglob (   pathname)
Return an iterator which yields the paths matching a pathname pattern.

The pattern may contain simple shell-style wildcards a la fnmatch.

Definition at line 17 of file glob.py.

00017 
00018 def iglob(pathname):
00019     """Return an iterator which yields the paths matching a pathname pattern.
00020 
00021     The pattern may contain simple shell-style wildcards a la fnmatch.
00022 
00023     """
00024     if not has_magic(pathname):
00025         if os.path.lexists(pathname):
00026             yield pathname
00027         return
00028     dirname, basename = os.path.split(pathname)
00029     if not dirname:
00030         for name in glob1(None, basename):
00031             yield name
00032         return
00033     if has_magic(dirname):
00034         dirs = iglob(dirname)
00035     else:
00036         dirs = [dirname]
00037     if has_magic(basename):
00038         glob_in_dir = glob1
00039     else:
00040         glob_in_dir = glob0
00041     for dirname in dirs:
00042         for name in glob_in_dir(dirname, basename):
00043             yield os.path.join(dirname, name)
00044 
00045 # These 2 helper functions non-recursively glob inside a literal directory.
00046 # They return a list of basenames. `glob1` accepts a pattern while `glob0`
00047 # takes a literal basename (so it only has to check for its existence).

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

list glob.__all__ = ["glob", "iglob"]

Definition at line 7 of file glob.py.

tuple glob.magic_check = re.compile('[*?[]')

Definition at line 74 of file glob.py.

Definition at line 75 of file glob.py.