Mercurial > babel > mirror
diff babel/messages/pofile.py @ 582:3fd7fb953633 trunk
fix handling of messages containing '\\n' (#171)
author | fschwarz |
---|---|
date | Fri, 03 Aug 2012 22:41:49 +0000 |
parents | 99706377c930 |
children | 5c9dba5dd311 |
line wrap: on
line diff
--- a/babel/messages/pofile.py +++ b/babel/messages/pofile.py @@ -40,11 +40,17 @@ :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.