Mercurial > babel > old > mirror
changeset 38:06b876ed5501
Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
author | cmlenz |
---|---|
date | Mon, 04 Jun 2007 21:30:52 +0000 |
parents | 3b23c60191e0 |
children | 52b98eca619f |
files | babel/catalog/extract.py babel/catalog/tests/extract.py |
diffstat | 2 files changed, 13 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/babel/catalog/extract.py +++ b/babel/catalog/extract.py @@ -229,7 +229,8 @@ 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[:]
--- 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__':