aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/glob.py
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools/glob.py')
-rw-r--r--setuptools/glob.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/setuptools/glob.py b/setuptools/glob.py
index f51b9c83..6c781de3 100644
--- a/setuptools/glob.py
+++ b/setuptools/glob.py
@@ -14,6 +14,7 @@ from setuptools.extern.six import binary_type
__all__ = ["glob", "iglob", "escape"]
+
def glob(pathname, recursive=False):
"""Return a list of paths matching a pathname pattern.
@@ -27,6 +28,7 @@ def glob(pathname, recursive=False):
"""
return list(iglob(pathname, recursive=recursive))
+
def iglob(pathname, recursive=False):
"""Return an iterator which yields the paths matching a pathname pattern.
@@ -44,6 +46,7 @@ def iglob(pathname, recursive=False):
assert not s
return it
+
def _iglob(pathname, recursive):
dirname, basename = os.path.split(pathname)
if not has_magic(pathname):
@@ -81,10 +84,12 @@ def _iglob(pathname, recursive):
for name in glob_in_dir(dirname, basename):
yield os.path.join(dirname, name)
+
# These 2 helper functions non-recursively glob inside a literal directory.
# They return a list of basenames. `glob1` accepts a pattern while `glob0`
# takes a literal basename (so it only has to check for its existence).
+
def glob1(dirname, pattern):
if not dirname:
if isinstance(pattern, binary_type):
@@ -97,6 +102,7 @@ def glob1(dirname, pattern):
return []
return fnmatch.filter(names, pattern)
+
def glob0(dirname, basename):
if not basename:
# `os.path.split()` returns an empty basename for paths ending with a
@@ -108,9 +114,11 @@ def glob0(dirname, basename):
return [basename]
return []
+
# This helper function recursively yields relative pathnames inside a literal
# directory.
+
def glob2(dirname, pattern):
assert _isrecursive(pattern)
yield pattern[:0]
@@ -139,6 +147,7 @@ def _rlistdir(dirname):
magic_check = re.compile('([*?[])')
magic_check_bytes = re.compile(b'([*?[])')
+
def has_magic(s):
if isinstance(s, binary_type):
match = magic_check_bytes.search(s)
@@ -146,12 +155,14 @@ def has_magic(s):
match = magic_check.search(s)
return match is not None
+
def _isrecursive(pattern):
if isinstance(pattern, binary_type):
return pattern == b'**'
else:
return pattern == '**'
+
def escape(pathname):
"""Escape all special characters.
"""