8000 gh-104484: Add parameter @case_sensitive to pathlib.PurePath.match() function by thirumurugan-git · Pull Request #104565 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-104484: Add parameter @case_sensitive to pathlib.PurePath.match() function #104565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 18, 2023
Prev Previous commit
Next Next commit
Refactor case sensitive check
  • Loading branch information
thirumurugan-git authored and thirumurugan-ka-15679 committed May 16, 2023
commit 73907a68368fa0f5fafeb50e28e2572df66bd595
8 changes: 4 additions & 4 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,10 @@ def match(self, path_pattern, case_sensitive=True):
elif len(pat_parts) > len(parts):
return False
for part, pat in zip(reversed(parts), reversed(pat_parts)):
if not case_sensitive:
# Convert the 'part' and 'pattern' to lowercase to ensure case insensitivity.
part, pat = part.lower(), pat.lower()
if not fnmatch.fnmatchcase(part, pat):
# If none of the flags are applied, the value of 'flags' would be 0.
flags = 0 if case_sensitive else re.I
match = re.compile(fnmatch.translate(pat), flags).match
if not match(part):
return False
return True

Expand Down
0