mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Made perlReToPythonRe always raise a ValueError instead of re.error.
This commit is contained in:
parent
388e17130d
commit
ed3d757081
@ -211,7 +211,10 @@ def perlReToPythonRe(s):
|
|||||||
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)
|
try:
|
||||||
|
return re.compile(regexp, flag)
|
||||||
|
except re.error, e:
|
||||||
|
raise ValueError, str(e)
|
||||||
|
|
||||||
def perlReToReplacer(s):
|
def perlReToReplacer(s):
|
||||||
"""Converts a string representation of a Perl regular expression (i.e.,
|
"""Converts a string representation of a Perl regular expression (i.e.,
|
||||||
|
@ -118,6 +118,7 @@ class UtilsTest(unittest.TestCase):
|
|||||||
self.failUnless(r.search('/'))
|
self.failUnless(r.search('/'))
|
||||||
r = utils.perlReToPythonRe('m/cat/i')
|
r = utils.perlReToPythonRe('m/cat/i')
|
||||||
self.failUnless(r.search('CAT'))
|
self.failUnless(r.search('CAT'))
|
||||||
|
self.assertRaises(ValueError, utils.perlReToPythonRe, 'm/?/')
|
||||||
|
|
||||||
def testPerlReToReplacer(self):
|
def testPerlReToReplacer(self):
|
||||||
f = utils.perlReToReplacer('s/foo/bar/')
|
f = utils.perlReToReplacer('s/foo/bar/')
|
||||||
|
Loading…
Reference in New Issue
Block a user