mirror of https://github.com/python/cpython
reapplied r74493 (after #6665 fix has been backported)
This commit is contained in:
parent
07728e9b46
commit
d6cfb8e0f8
|
@ -344,7 +344,9 @@ def translate_pattern (pattern, anchor=1, prefix=None, is_regex=0):
|
|||
pattern_re = ''
|
||||
|
||||
if prefix is not None:
|
||||
prefix_re = (glob_to_re(prefix))[0:-1] # ditch trailing $
|
||||
# ditch end of pattern character
|
||||
empty_pattern = glob_to_re('')
|
||||
prefix_re = (glob_to_re(prefix))[:-len(empty_pattern)]
|
||||
pattern_re = "^" + os.path.join(prefix_re, ".*" + pattern_re)
|
||||
else: # no prefix -- respect anchor flag
|
||||
if anchor:
|
||||
|
|
|
@ -6,15 +6,15 @@ class FileListTestCase(unittest.TestCase):
|
|||
|
||||
def test_glob_to_re(self):
|
||||
# simple cases
|
||||
self.assertEquals(glob_to_re('foo*'), 'foo[^/]*$')
|
||||
self.assertEquals(glob_to_re('foo?'), 'foo[^/]$')
|
||||
self.assertEquals(glob_to_re('foo??'), 'foo[^/][^/]$')
|
||||
self.assertEquals(glob_to_re('foo*'), 'foo[^/]*\\Z(?ms)')
|
||||
self.assertEquals(glob_to_re('foo?'), 'foo[^/]\\Z(?ms)')
|
||||
self.assertEquals(glob_to_re('foo??'), 'foo[^/][^/]\\Z(?ms)')
|
||||
|
||||
# special cases
|
||||
self.assertEquals(glob_to_re(r'foo\\*'), r'foo\\\\[^/]*$')
|
||||
self.assertEquals(glob_to_re(r'foo\\\*'), r'foo\\\\\\[^/]*$')
|
||||
self.assertEquals(glob_to_re('foo????'), r'foo[^/][^/][^/][^/]$')
|
||||
self.assertEquals(glob_to_re(r'foo\\??'), r'foo\\\\[^/][^/]$')
|
||||
self.assertEquals(glob_to_re(r'foo\\*'), r'foo\\\\[^/]*\Z(?ms)')
|
||||
self.assertEquals(glob_to_re(r'foo\\\*'), r'foo\\\\\\[^/]*\Z(?ms)')
|
||||
self.assertEquals(glob_to_re('foo????'), r'foo[^/][^/][^/][^/]\Z(?ms)')
|
||||
self.assertEquals(glob_to_re(r'foo\\??'), r'foo\\\\[^/][^/]\Z(?ms)')
|
||||
|
||||
def test_suite():
|
||||
return unittest.makeSuite(FileListTestCase)
|
||||
|
|
Loading…
Reference in New Issue