with more than 7 significant digits (#183)
* fix format_date() with datetime parameter (#282, patch from Xavier Morel)
* fix format_decimal() with small Decimal values (#214, patch from George Lund)
+ * fix handling of messages containing '\\n' (#171)
Version 0.9.6
:return: the unescaped string
:rtype: `str` or `unicode`
"""
- return string[1:-1].replace('\\\\', '\\') \
- .replace('\\t', '\t') \
- .replace('\\r', '\r') \
- .replace('\\n', '\n') \
- .replace('\\"', '\"')
+ def replace_escapes(match):
+ m = match.group(1)
+ if m == 'n':
+ return '\n'
+ elif m == 't':
+ return '\t'
+ elif m == 'r':
+ return '\r'
+ # m is \ or "
+ return m
+ return re.compile(r'\\([\\trn"])').sub(replace_escapes, string[1:-1])
def denormalize(string):
r"""Reverse the normalization done by the `normalize` function.
self.assertEqual(catalog['missing line number'].locations, [])
self.assertEqual(catalog['broken line number'].locations, [])
+
+class PofileFunctionsTestCase(unittest.TestCase):
+
+ def test_unescape(self):
+ escaped = u'"Say:\\n \\"hello, world!\\"\\n"'
+ unescaped = u'Say:\n "hello, world!"\n'
+ self.assertNotEqual(unescaped, escaped)
+ self.assertEqual(unescaped, pofile.unescape(escaped))
+
+ def test_unescape_of_quoted_newline(self):
+ # regression test for #198
+ self.assertEqual(r'\n', pofile.unescape(r'"\\n"'))
+
+
def suite():
suite = unittest.TestSuite()
suite.addTest(doctest.DocTestSuite(pofile, optionflags=doctest.ELLIPSIS))
suite.addTest(unittest.makeSuite(ReadPoTestCase))
suite.addTest(unittest.makeSuite(WritePoTestCase))
+ suite.addTest(unittest.makeSuite(PofileFunctionsTestCase))
return suite
if __name__ == '__main__':