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
8000

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
Next Next commit
Add parameter @case_sensitive to pathlib.PurePath.match() function
  • Loading branch information
thirumurugan-git authored and thirumurugan-ka-15679 committed May 16, 2023
commit 473eeaf2a003b9b8f34f2bc0077575c4041983f2
5 changes: 4 additions & 1 deletion Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def is_reserved(self):
name = self._tail[-1].partition('.')[0].partition(':')[0].rstrip(' ')
return name.upper() in _WIN_RESERVED_NAMES

def match(self, path_pattern):
def match(self, path_pattern, case_sensitive=True):
"""
Return True if this path matches the given pattern.
"""
Expand All @@ -695,6 +695,9 @@ def match(self, path_pattern):
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):
return False
return True
Expand Down
0