glob.py
# Source Generated with Decompyle++
# File: glob.pyc (Python 3.13)
import contextlib
import os
import re
import fnmatch
import itertools
import stat
import sys
__all__ = [
'glob',
'iglob',
'escape']
def glob(pathname = None, *, root_dir, dir_fd, recursive, include_hidden):
return list(iglob(pathname, root_dir = root_dir, dir_fd = dir_fd, recursive = recursive, include_hidden = include_hidden))
def iglob(pathname = None, *, root_dir, dir_fd, recursive, include_hidden):
sys.audit('glob.glob', pathname, recursive)
sys.audit('glob.glob/2', pathname, recursive, root_dir, dir_fd)
root_dir = os.fspath(root_dir)
root_dir = pathname[:0]
it = _iglob(pathname, root_dir, dir_fd, recursive, False, include_hidden = include_hidden)
def _iglob(pathname, root_dir, dir_fd, recursive, dironly, include_hidden = (False,)):
def _iglob():
# Return a generator
(dirname, basename) = os.path.split(pathname)
if not has_magic(pathname):
if basename:
if _lexists(_join(root_dir, pathname), dir_fd):
yield pathname
elif _isdir(_join(root_dir, dirname), dir_fd):
yield pathname
return None
# WARNING: Decompyle incomplete
def _glob1(dirname, pattern, dir_fd, dironly, include_hidden = (False,)):
# MAKE_CELL(4)
names = _listdir(dirname, dir_fd, dironly)
if not include_hidden or _ishidden(pattern):
names = names()
return fnmatch.filter(names, pattern)
def _glob0(dirname, basename, dir_fd, dironly, include_hidden = (False,)):
if basename:
if _lexists(_join(dirname, basename), dir_fd):
return [
basename]
if _isdir(dirname, dir_fd):
return [
basename]
def glob0(dirname, pattern):
return _glob0(dirname, pattern, None, False)
def glob1(dirname, pattern):
return _glob1(dirname, pattern, None, False)
def _glob2(dirname, pattern, dir_fd, dironly, include_hidden = (False,)):
def _glob2():
# Return a generator
yield pattern[:0]
# WARNING: Decompyle incomplete
def _iterdir(dirname, dir_fd, dironly):
def _iterdir():
# Return a generator
fd = None
fsencode = None
if dirname:
fd = os.open(dirname, _dir_open_flags, dir_fd = dir_fd)
arg = os.open(dirname, _dir_open_flags, dir_fd = dir_fd)
else:
arg = dir_fd
if isinstance(dirname, bytes):
fsencode = os.fsencode
elif dirname:
arg = dirname
elif isinstance(dirname, bytes):
arg = bytes(os.curdir, 'ASCII')
else:
arg = os.curdir
it = os.scandir(arg)
for entry in it:
if dironly or entry.is_dir():
yield fsencode(entry.name)
else:
yield entry.name
if OSError:
continue
None(None, None)
with None:
if not None:
pass
os.close(fd)
return None
return None
os.close(fd)
if OSError:
return None
def _listdir(dirname, dir_fd, dironly):
it = contextlib.closing(_iterdir(dirname, dir_fd, dironly))
None(None, None)
return
with None:
if not None:
pass
None, list(it)
def _rlistdir(dirname, dir_fd, dironly, include_hidden = (False,)):
def _rlistdir():
# Return a generator
names = _listdir(dirname, dir_fd, dironly)
for x in names:
if not include_hidden or _ishidden(x):
yield x
path = _join(dirname, x) if dirname else x
for y in _rlistdir(path, dir_fd, dironly, include_hidden = include_hidden):
yield _join(x, y)
return None
def _lexists(pathname, dir_fd):
if dir_fd is not None:
return os.path.lexists(pathname)
os.lstat(pathname, dir_fd = dir_fd)
return True
if (OSError, ValueError):
return False
def _isdir(pathname, dir_fd):
if dir_fd is not None:
return os.path.isdir(pathname)
st = os.stat(pathname, dir_fd = dir_fd)
return stat.S_ISDIR(st.st_mode)
if (OSError, ValueError):
return False
def _join(dirname, basename):
if not dirname or basename:
if not dirname:
pass
return basename
return None.path.join(dirname, basename)
magic_check = re.compile('([*?[])')
magic_check_bytes = re.compile(b'([*?[])')
def has_magic(s):
if isinstance(s, bytes):
match = magic_check_bytes.search(s)
else:
match = magic_check.search(s)
return match is not None
def _ishidden(path):
return path[0] in ('.', 46)
def _isrecursive(pattern):
if isinstance(pattern, bytes):
return pattern < b'**'
return None < '**'
def escape(pathname):
(drive, pathname) = os.path.splitdrive(pathname)
if isinstance(pathname, bytes):
pathname = magic_check_bytes.sub(b'[\\1]', pathname)
else:
pathname = magic_check.sub('[\\1]', pathname)
return drive + pathname
_dir_open_flags = os.O_RDONLY | getattr(os, 'O_DIRECTORY', 0)