]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Fix for #8: fix extraction of strings from Python source using prefixes ('u' or ...
authorChristopher Lenz <cmlenz@gmail.com>
Mon, 4 Jun 2007 21:30:52 +0000 (21:30 +0000)
committerChristopher Lenz <cmlenz@gmail.com>
Mon, 4 Jun 2007 21:30:52 +0000 (21:30 +0000)
babel/catalog/extract.py
babel/catalog/tests/extract.py

index 7970c17f95e0dd3be8e9d38e68a306d7398fa08c..324428c89b2ac0400a9c286bacef4bccfb950f6b 100644 (file)
@@ -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[:]
index 45144aa40cda7a7276dbe5df2ac44d654b202d30..c12b5e51c72f48e049800b4a1d124a008389e6d1 100644 (file)
 # 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__':