Made perlReToPythonRe always raise a ValueError instead of re.error.

This commit is contained in:
Jeremy Fincher 2003-10-15 05:07:07 +00:00
parent 388e17130d
commit ed3d757081
2 changed files with 5 additions and 1 deletions

View File

@ -211,7 +211,10 @@ def perlReToPythonRe(s):
flag |= getattr(re, c)
except AttributeError:
raise ValueError, 'Invalid flag: %s' % c
return re.compile(regexp, flag)
try:
return re.compile(regexp, flag)
except re.error, e:
raise ValueError, str(e)
def perlReToReplacer(s):
"""Converts a string representation of a Perl regular expression (i.e.,

View File

@ -118,6 +118,7 @@ class UtilsTest(unittest.TestCase):
self.failUnless(r.search('/'))
r = utils.perlReToPythonRe('m/cat/i')
self.failUnless(r.search('CAT'))
self.assertRaises(ValueError, utils.perlReToPythonRe, 'm/?/')
def testPerlReToReplacer(self):
f = utils.perlReToReplacer('s/foo/bar/')