Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def split_translate(self, pattern, flags):
"""Translate pattern to regex after splitting."""
return fnmatch.translate(pattern, flags=flags | fnmatch.SPLIT)
def test_posix_range(self):
"""Test posix range."""
p = fnmatch.translate(r'[[:ascii:]-z]', flags=self.flags | fnmatch.U | fnmatch.C)
if util.PY36:
self.assertEqual(p, (['^(?s:[\x00-\x7f\\-z])$'], []))
else:
self.assertEqual(p, (['(?s)^(?:[\x00-\x7f\\-z])$'], []))
p = fnmatch.translate(r'[a-[:ascii:]-z]', flags=self.flags | fnmatch.U | fnmatch.C)
if util.PY36:
self.assertEqual(p, (['^(?s:[a\\-\x00-\x7f\\-z])$'], []))
else:
self.assertEqual(p, (['(?s)^(?:[a\\-\x00-\x7f\\-z])$'], []))
if util.PY36:
self.assertEqual(p1, [r'^(?s:test\ m)$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:test\ m)$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate(r'test[\\]test', flags=flags | fnmatch.R)
if util.PY36:
self.assertEqual(p1, [r'^(?s:test[\\]test)$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:test[\\]test)$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate('test[\\', flags=flags)
if util.PY36:
self.assertEqual(p1, [r'^(?s:test\[\\)$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:test\[\\)$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate(r'test\44test', flags=flags | fnmatch.R)
if util.PY36:
self.assertEqual(p1, [r'^(?s:test\$test)$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:test\$test)$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate(r'test\44', flags=flags | fnmatch.R)
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:testppppp)$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate(
r'test[\x70][\u0070][\U00000070][\160][\N{LATIN SMALL LETTER P}]', flags=flags | fnmatch.R
)
if util.PY36:
self.assertEqual(p1, [r'^(?s:test[p][p][p][p][p])$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:test[p][p][p][p][p])$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate(r'test\t\m', flags=flags | fnmatch.R)
if util.PY36:
self.assertEqual(p1, [r'^(?s:test\ m)$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:test\ m)$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate(r'test[\\]test', flags=flags | fnmatch.R)
if util.PY36:
self.assertEqual(p1, [r'^(?s:test[\\]test)$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:test[\\]test)$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate('test[\\', flags=flags)
def test_special_escapes(self, mock__iscase_sensitive):
"""Test wildcard character notations."""
flags = self.flags | fnmatch.U
_wcparse._compile.cache_clear()
p1, p2 = fnmatch.translate(
r'test\x70\u0070\U00000070\160\N{LATIN SMALL LETTER P}', flags=flags | fnmatch.R
)
if util.PY36:
self.assertEqual(p1, [r'^(?s:testppppp)$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:testppppp)$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate(
r'test[\x70][\u0070][\U00000070][\160][\N{LATIN SMALL LETTER P}]', flags=flags | fnmatch.R
)
if util.PY36:
self.assertEqual(p1, [r'^(?s:test[p][p][p][p][p])$'])
self.assertEqual(p2, [])
else:
p1, p2 = fnmatch.translate(r'test\400', flags=flags | fnmatch.R)
if util.PY37:
self.assertEqual(p1, [r'^(?s:testĀ)$'])
self.assertEqual(p2, [])
elif util.PY36:
self.assertEqual(p1, [r'^(?s:test\Ā)$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:test\Ā)$'])
self.assertEqual(p2, [])
with pytest.raises(SyntaxError):
fnmatch.translate(r'test\N', flags=flags | fnmatch.R)
with pytest.raises(SyntaxError):
fnmatch.translate(r'test\Nx', flags=flags | fnmatch.R)
with pytest.raises(SyntaxError):
fnmatch.translate(r'test\N{', flags=flags | fnmatch.R)
if util.PY36:
self.assertEqual(p1, [r'^(?s:test[p][p][p][p][p])$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:test[p][p][p][p][p])$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate(r'test\t\m', flags=flags | fnmatch.R)
if util.PY36:
self.assertEqual(p1, [r'^(?s:test\ m)$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:test\ m)$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate(r'test[\\]test', flags=flags | fnmatch.R)
if util.PY36:
self.assertEqual(p1, [r'^(?s:test[\\]test)$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:test[\\]test)$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate('test[\\', flags=flags)
if util.PY36:
self.assertEqual(p1, [r'^(?s:test\[\\)$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:test\[\\)$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate(r'test\44test', flags=flags | fnmatch.R)
if util.PY36:
self.assertEqual(p1, [r'^(?s:test[\\]test)$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:test[\\]test)$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate('test[\\', flags=flags)
if util.PY36:
self.assertEqual(p1, [r'^(?s:test\[\\)$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:test\[\\)$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate(r'test\44test', flags=flags | fnmatch.R)
if util.PY36:
self.assertEqual(p1, [r'^(?s:test\$test)$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:test\$test)$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate(r'test\44', flags=flags | fnmatch.R)
if util.PY36:
self.assertEqual(p1, [r'^(?s:test\$)$'])
self.assertEqual(p2, [])
else:
self.assertEqual(p1, [r'(?s)^(?:test\$)$'])
self.assertEqual(p2, [])
p1, p2 = fnmatch.translate(r'test\400', flags=flags | fnmatch.R)
def test_default_translate(self):
"""Test default with exclusion in translation."""
self.assertTrue(len(fnmatch.translate('!test', flags=fnmatch.N | fnmatch.A)[0]) == 1)
self.assertTrue(len(fnmatch.translate(b'!test', flags=fnmatch.N | fnmatch.A)[0]) == 1)