Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into gh-77609-glob-follow-symlinks-triple-star
  • Loading branch information
barneygale committed May 7, 2023
commit 83001afc5b698ae02f386acf21878a458d2c2778
21 changes: 16 additions & 5 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,28 @@ def _is_case_sensitive(flavour):
# Globbing helpers
#


@functools.lru_cache()
def _make_selector(pattern_parts, flavour, case_sensitive):
pat = pattern_parts[0]
if not pat:
return _TerminatingSelector()
if pat == '**' or pat == '***':
cls = _RecursiveWildcardSelector
elif pat == '..':
cls = _ParentSelector
elif '**' in pat:
raise ValueError("Invalid pattern: '**' can only be an entire path component")
child_parts_idx = 1
while child_parts_idx < len(pattern_parts):
child_part = pattern_parts[child_parts_idx]
if child_part == '***':
pat = '***'
elif child_part != '**':
break
child_parts_idx += 1
child_parts = pattern_parts[child_parts_idx:]
for child_part in child_parts:
if child_part == '**' or child_part == '***':
cls = _DoubleRecursiveWildcardSelector
break
else:
cls = _RecursiveWildcardSelector
else:
child_parts = pattern_parts[1:]
if pat == '..':
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,9 @@ def _check(glob, expected):
p = P(BASE)
if os_helper.can_symlink():
_check(p.glob("***/fileB"), ["dirB/fileB", "dirA/linkC/fileB", "linkB/fileB"])
_check(p.glob("***/***/fileB"), ["dirB/fileB", "dirA/linkC/fileB", "linkB/fileB"])
_check(p.glob("***/**/fileB"), ["dirB/fileB", "dirA/linkC/fileB", "linkB/fileB"])
_check(p.glob("**/***/fileB"), ["dirB/fileB", "dirA/linkC/fileB", "linkB/fileB"])
_check(p.glob("***/*/fileA"), [])
_check(p.glob("***/*/fileB"), ["dirB/fileB", "linkB/fileB", "dirA/linkC/fileB"])
_check(p.glob("***/file*"), ["fileA", "dirA/linkC/fileB", "dirB/fileB", "dirC/fileC",
Expand All @@ -2005,9 +2008,11 @@ def _check(glob, expected):
p = P(BASE, "dirC")
_check(p.glob("***/*"), ["dirC/fileC", "dirC/novel.txt", "dirC/dirD", "dirC/dirD/fileD"])
_check(p.glob("***/file*"), ["dirC/fileC", "dirC/dirD/fileD"])
_check(p.glob("dir*/***"), ["dirC/dirD"])
_check(p.glob("***/*/*"), ["dirC/dirD/fileD"])
_check(p.glob("***/*/"), ["dirC/dirD"])
_check(p.glob("***"), ["dirC", "dirC/dirD"])
_check(p.glob("***/***"), ["dirC", "dirC/dirD"])
_check(p.glob("***/*.txt"), ["dirC/novel.txt"])
_check(p.glob("***/*.*"), ["dirC/novel.txt"])

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.