Skip to content

Commit

Permalink
fix ScanPoliciesManager support for compiled regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
mjurbanski-reef committed Nov 9, 2023
1 parent f04cca5 commit c53cd6e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
* Fix ScanPoliciesManager support for compiled regexes

### Infrastructure
* Fix readthedocs build by updating to v2 configuration schema
* Fix spellcheck erroring out on LICENSE file
Expand Down
6 changes: 4 additions & 2 deletions b2sdk/scan/policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def matches(self, s):
return any(c.match(s) is not None for c in self._compiled_list)


def convert_dir_regex_to_dir_prefix_regex(dir_regex):
def convert_dir_regex_to_dir_prefix_regex(dir_regex: str | re.Pattern) -> str:
"""
The patterns used to match directory names (and file names) are allowed
to match a prefix of the name. This 'feature' was unintentional, but is
Expand All @@ -65,8 +65,10 @@ def convert_dir_regex_to_dir_prefix_regex(dir_regex):
either the regex ends in '$' or does not.
:param dir_regex: a regular expression string or literal
:type dir_regex: str
:return: a regular expression string which matches the directory prefix
"""
if isinstance(dir_regex, re.Pattern):
dir_regex = dir_regex.pattern
if dir_regex.endswith('$'):
return dir_regex[:-1] + r'/'
else:
Expand Down
12 changes: 12 additions & 0 deletions test/unit/scan/test_scan_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,15 @@ def test_illegal_timestamp(self, param, exception):
}
with pytest.raises(exception):
ScanPoliciesManager(**kwargs)

@pytest.mark.apiver(from_ver=2)
def test_re_pattern_argument_support(self):
kwargs = {
param: (re.compile(r".*"),)
for param in (
"exclude_dir_regexes",
"exclude_file_regexes",
"include_file_regexes",
)
}
ScanPoliciesManager(**kwargs)

0 comments on commit c53cd6e

Please sign in to comment.