Sha256: 3e1a9e5fea6b9b8c588fb8656fd29bd06eb1a99cd1401e5d59fc3c93ad0d5efc

Contents?: true

Size: 1.41 KB

Versions: 30

Compression:

Stored size: 1.41 KB

Contents

"""Filename globbing utility."""

import os
import fnmatch
import re

__all__ = ["glob"]

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

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

    """
    if not has_magic(pathname):
        if os.path.exists(pathname):
            return [pathname]
        else:
            return []
    dirname, basename = os.path.split(pathname)
    if not dirname:
        return glob1(os.curdir, basename)
    elif has_magic(dirname):
        list = glob(dirname)
    else:
        list = [dirname]
    if not has_magic(basename):
        result = []
        for dirname in list:
            if basename or os.path.isdir(dirname):
                name = os.path.join(dirname, basename)
                if os.path.exists(name):
                    result.append(name)
    else:
        result = []
        for dirname in list:
            sublist = glob1(dirname, basename)
            for name in sublist:
                result.append(os.path.join(dirname, name))
    return result

def glob1(dirname, pattern):
    if not dirname: dirname = os.curdir
    try:
        names = os.listdir(dirname)
    except os.error:
        return []
    if pattern[0]!='.':
        names=filter(lambda x: x[0]!='.',names)
    return fnmatch.filter(names,pattern)


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

def has_magic(s):
    return magic_check.search(s) is not None

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
rubyfox-server-2.19.2.0 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.17.3.2 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.17.3.1 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.17.3.0 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.16.3.2 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.16.3.1 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.16.0.4 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.16.0.3 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.16.0.2 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.16.0.1 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.16.0.0 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.13.7.3 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.13.6.2 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.13.6.1 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.13.5.1 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.13.4.1 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.13.3.1 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.12.5.1 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.12.5.0 lib/rubyfox/server/data/lib/Lib/glob.py
rubyfox-server-2.12.4.0 lib/rubyfox/server/data/lib/Lib/glob.py