| 58 | return it |
| 59 | |
| 60 | def _iglob(pathname, root_dir, dir_fd, recursive, dironly, |
| 61 | include_hidden=False): |
| 62 | dirname, basename = os.path.split(pathname) |
| 63 | if not has_magic(pathname): |
| 64 | assert not dironly |
| 65 | if basename: |
| 66 | if _lexists(_join(root_dir, pathname), dir_fd): |
| 67 | yield pathname |
| 68 | else: |
| 69 | # Patterns ending with a slash should match only directories |
| 70 | if _isdir(_join(root_dir, dirname), dir_fd): |
| 71 | yield pathname |
| 72 | return |
| 73 | if not dirname: |
| 74 | if recursive and _isrecursive(basename): |
| 75 | yield from _glob2(root_dir, basename, dir_fd, dironly, |
| 76 | include_hidden=include_hidden) |
| 77 | else: |
| 78 | yield from _glob1(root_dir, basename, dir_fd, dironly, |
| 79 | include_hidden=include_hidden) |
| 80 | return |
| 81 | # `os.path.split()` returns the argument itself as a dirname if it is a |
| 82 | # drive or UNC path. Prevent an infinite recursion if a drive or UNC path |
| 83 | # contains magic characters (i.e. r'\\?\C:'). |
| 84 | if dirname != pathname and has_magic(dirname): |
| 85 | dirs = _iglob(dirname, root_dir, dir_fd, recursive, True, |
| 86 | include_hidden=include_hidden) |
| 87 | else: |
| 88 | dirs = [dirname] |
| 89 | if has_magic(basename): |
| 90 | if recursive and _isrecursive(basename): |
| 91 | glob_in_dir = _glob2 |
| 92 | else: |
| 93 | glob_in_dir = _glob1 |
| 94 | else: |
| 95 | glob_in_dir = _glob0 |
| 96 | for dirname in dirs: |
| 97 | for name in glob_in_dir(_join(root_dir, dirname), basename, dir_fd, dironly, |
| 98 | include_hidden=include_hidden): |
| 99 | yield os.path.join(dirname, name) |
| 100 | |
| 101 | # These 2 helper functions non-recursively glob inside a literal directory. |
| 102 | # They return a list of basenames. _glob1 accepts a pattern while _glob0 |