Index: Lib/glob.py =================================================================== --- Lib/glob.py (revision 87951) +++ Lib/glob.py (working copy) @@ -1,9 +1,9 @@ """Filename globbing utility.""" -import sys import os import re import fnmatch +from warnings import warn as _warn __all__ = ["glob", "iglob"] @@ -21,32 +21,32 @@ The pattern may contain simple shell-style wildcards a la fnmatch. """ - if not has_magic(pathname): + if not _has_magic(pathname): if os.path.lexists(pathname): yield pathname return dirname, basename = os.path.split(pathname) if not dirname: - for name in glob1(None, basename): + for name in _glob1(None, basename): yield name return - if has_magic(dirname): + if _has_magic(dirname): dirs = iglob(dirname) else: dirs = [dirname] - if has_magic(basename): - glob_in_dir = glob1 + if _has_magic(basename): + glob_in_dir = _glob1 else: - glob_in_dir = glob0 + glob_in_dir = _glob0 for dirname in dirs: 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` +# 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): +def _glob1(dirname, pattern): if not dirname: if isinstance(pattern, bytes): dirname = bytes(os.curdir, 'ASCII') @@ -60,7 +60,7 @@ names = [x for x in names if x[0] != '.'] return fnmatch.filter(names, pattern) -def glob0(dirname, basename): +def _glob0(dirname, basename): if basename == '': # `os.path.split()` returns an empty basename for paths ending with a # directory separator. 'q*x/' should match only directories. @@ -72,12 +72,27 @@ return [] -magic_check = re.compile('[*?[]') -magic_check_bytes = re.compile(b'[*?[]') +_magic_check = re.compile('[*?[]') +_magic_check_bytes = re.compile(b'[*?[]') -def has_magic(s): +def _has_magic(s): if isinstance(s, bytes): - match = magic_check_bytes.search(s) + match = _magic_check_bytes.search(s) else: - match = magic_check.search(s) + match = _magic_check.search(s) return match is not None + +def glob1(*args): + _warn("The glob.glob1() function is deprecated", + DeprecationWarning, 2) + return _glob1(*args) + +def glob0(*args): + _warn("The glob.glob0() function is deprecated", + DeprecationWarning, 2) + return _glob0(*args) + +def has_magic(*args): + _warn("The glob.has_magic() function is deprecated", + DeprecationWarning, 2) + return _has_magic(*args)