From: Christopher Lenz Date: Mon, 4 Jun 2007 21:30:52 +0000 (+0000) Subject: Fix for #8: fix extraction of strings from Python source using prefixes ('u' or ... X-Git-Tag: 1.0~593 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e0c90d886bebe3a267860b36dbabfd9f83ed52a;p=thirdparty%2Fbabel.git Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes. --- diff --git a/babel/catalog/extract.py b/babel/catalog/extract.py index 7970c17f..324428c8 100644 --- a/babel/catalog/extract.py +++ b/babel/catalog/extract.py @@ -229,7 +229,8 @@ def extract_python(fileobj, keywords, options): elif tok == STRING: if lineno is None: lineno = stup[0] - buf.append(value[1:-1]) + # Unwrap quotes in a safe manner + buf.append(eval(value, {'__builtins__':{}}, {})) elif tok == OP and value == ',': messages.append(''.join(buf)) del buf[:] diff --git a/babel/catalog/tests/extract.py b/babel/catalog/tests/extract.py index 45144aa4..c12b5e51 100644 --- a/babel/catalog/tests/extract.py +++ b/babel/catalog/tests/extract.py @@ -12,13 +12,24 @@ # history and logs, available at http://babel.edgewall.org/log/. import doctest +from StringIO import StringIO import unittest from babel.catalog import extract + +class ExtractPythonTestCase(unittest.TestCase): + + def test_unicode_string_arg(self): + buf = StringIO("msg = _(u'Foo Bar')") + messages = list(extract.extract_python(buf, ('_',), {})) + self.assertEqual('Foo Bar', messages[0][2]) + + def suite(): suite = unittest.TestSuite() suite.addTest(doctest.DocTestSuite(extract)) + suite.addTest(unittest.makeSuite(ExtractPythonTestCase)) return suite if __name__ == '__main__':