Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_expansion_limt(self):
"""Test expansion limit."""
with self.assertRaises(_wcparse.PatternLimitException):
_wcparse.compile('{1..11}', _wcparse.BRACE, 10)
with self.assertRaises(_wcparse.PatternLimitException):
_wcparse.compile('|'.join(['a'] * 11), _wcparse.SPLIT, 10)
with self.assertRaises(_wcparse.PatternLimitException):
_wcparse.compile(
'{{{},{}}}'.format('|'.join(['a'] * 6), '|'.join(['a'] * 5)),
_wcparse.SPLIT | _wcparse.BRACE, 10
)
def test_compile_unique_optimization_okay(self):
"""Test that redundant patterns are reduced in compile."""
self.assertEqual(len(_wcparse.compile('|'.join(['a'] * 10), _wcparse.SPLIT, 10)), 1)
def test_expansion_limt(self):
"""Test expansion limit."""
with self.assertRaises(_wcparse.PatternLimitException):
_wcparse.compile('{1..11}', _wcparse.BRACE, 10)
with self.assertRaises(_wcparse.PatternLimitException):
_wcparse.compile('|'.join(['a'] * 11), _wcparse.SPLIT, 10)
with self.assertRaises(_wcparse.PatternLimitException):
_wcparse.compile(
'{{{},{}}}'.format('|'.join(['a'] * 6), '|'.join(['a'] * 5)),
_wcparse.SPLIT | _wcparse.BRACE, 10
)
def test_compile_expansion_okay(self):
"""Test expansion is okay."""
self.assertEqual(len(_wcparse.compile('{1..10}', _wcparse.BRACE)), 10)
def test_expansion_limt(self):
"""Test expansion limit."""
with self.assertRaises(_wcparse.PatternLimitException):
_wcparse.compile('{1..11}', _wcparse.BRACE, 10)
with self.assertRaises(_wcparse.PatternLimitException):
_wcparse.compile('|'.join(['a'] * 11), _wcparse.SPLIT, 10)
with self.assertRaises(_wcparse.PatternLimitException):
_wcparse.compile(
'{{{},{}}}'.format('|'.join(['a'] * 6), '|'.join(['a'] * 5)),
_wcparse.SPLIT | _wcparse.BRACE, 10
)
def globfilter(filenames, patterns, *, flags=0, root_dir=None, limit=_wcparse.PATTERN_LIMIT):
"""Filter names using pattern."""
is_bytes = isinstance(patterns[0], bytes) if not isinstance(patterns, (bytes, str)) else isinstance(patterns, bytes)
if root_dir is not None:
root_dir = util.fscodec(root_dir, is_bytes)
matches = []
flags = _flag_transform(flags)
unix = _wcparse.is_unix_style(flags)
obj = _wcparse.compile(patterns, flags, limit)
for filename in filenames:
temp = util.fscodec(filename, is_bytes)
if not unix:
temp = _wcparse.norm_slash(temp, flags)
if obj.match(temp, root_dir):
matches.append(filename)
return matches
def _compile_wildcard(self, pattern, pathname=False):
"""Compile or format the wildcard inclusion/exclusion pattern."""
flags = self.flags
if pathname:
flags |= _PATHNAME | _ANCHOR
if self.matchbase:
flags |= MATCHBASE
return _wcparse.compile(pattern, flags, self.limit) if pattern else None
"""
Check if filename matches pattern.
By default case sensitivity is determined by the file system,
but if `case_sensitive` is set, respect that instead.
"""
is_bytes = isinstance(patterns[0], bytes) if not isinstance(patterns, (bytes, str)) else isinstance(patterns, bytes)
if root_dir is not None:
root_dir = util.fscodec(root_dir, is_bytes)
flags = _flag_transform(flags)
filename = util.fscodec(filename, is_bytes)
if not _wcparse.is_unix_style(flags):
filename = _wcparse.norm_slash(filename, flags)
return _wcparse.compile(patterns, flags, limit).match(filename, root_dir=root_dir)