Found bug in perlReToPythonRe and fixed it.

This commit is contained in:
Jeremy Fincher 2003-08-30 18:39:19 +00:00
parent 167acefe8a
commit 1cd7ccbfa4
2 changed files with 5 additions and 1 deletions

View File

@ -227,7 +227,7 @@ def perlReToPythonRe(s):
flag = 0 flag = 0
try: try:
for c in flags.upper(): for c in flags.upper():
flag &= getattr(re, c) flag |= getattr(re, c)
except AttributeError: except AttributeError:
raise ValueError, 'Invalid flag: %s' % c raise ValueError, 'Invalid flag: %s' % c
return re.compile(regexp, flag) return re.compile(regexp, flag)

View File

@ -113,6 +113,8 @@ class UtilsTest(unittest.TestCase):
self.failUnless(r.search('foo')) self.failUnless(r.search('foo'))
r = utils.perlReToPythonRe('m/\\//') r = utils.perlReToPythonRe('m/\\//')
self.failUnless(r.search('/')) self.failUnless(r.search('/'))
r = utils.perlReToPythonRe('m/cat/i')
self.failUnless(r.search('CAT'))
def testPerlReToReplacer(self): def testPerlReToReplacer(self):
f = utils.perlReToReplacer('s/foo/bar/') f = utils.perlReToReplacer('s/foo/bar/')
@ -127,6 +129,8 @@ class UtilsTest(unittest.TestCase):
self.assertEqual(f('foobarbaz'), 'foorz') self.assertEqual(f('foobarbaz'), 'foorz')
f = utils.perlReToReplacer('s/ba\\///g') f = utils.perlReToReplacer('s/ba\\///g')
self.assertEqual(f('fooba/rba/z'), 'foorz') self.assertEqual(f('fooba/rba/z'), 'foorz')
f = utils.perlReToReplacer('s/cat/dog/i')
self.assertEqual(f('CATFISH'), 'dogFISH')
def testFindBinaryInPath(self): def testFindBinaryInPath(self):
if os.name == 'posix': if os.name == 'posix':