From ed3d757081caba4f1c7175f640dd2eac0fc8754b Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Wed, 15 Oct 2003 05:07:07 +0000 Subject: [PATCH] Made perlReToPythonRe always raise a ValueError instead of re.error. --- src/utils.py | 5 ++++- test/test_utils.py | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils.py b/src/utils.py index ae89259ce..3a5108a42 100755 --- a/src/utils.py +++ b/src/utils.py @@ -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., diff --git a/test/test_utils.py b/test/test_utils.py index 7a9ac44ee..a3abbc289 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -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/')