comparison 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
comparison
equal deleted inserted replaced
581:99706377c930 582:3fd7fb953633
38 38
39 :param string: the string to unescape 39 :param string: the string to unescape
40 :return: the unescaped string 40 :return: the unescaped string
41 :rtype: `str` or `unicode` 41 :rtype: `str` or `unicode`
42 """ 42 """
43 return string[1:-1].replace('\\\\', '\\') \ 43 def replace_escapes(match):
44 .replace('\\t', '\t') \ 44 m = match.group(1)
45 .replace('\\r', '\r') \ 45 if m == 'n':
46 .replace('\\n', '\n') \ 46 return '\n'
47 .replace('\\"', '\"') 47 elif m == 't':
48 return '\t'
49 elif m == 'r':
50 return '\r'
51 # m is \ or "
52 return m
53 return re.compile(r'\\([\\trn"])').sub(replace_escapes, string[1:-1])
48 54
49 def denormalize(string): 55 def denormalize(string):
50 r"""Reverse the normalization done by the `normalize` function. 56 r"""Reverse the normalization done by the `normalize` function.
51 57
52 >>> print denormalize(r'''"" 58 >>> print denormalize(r'''""
Copyright (C) 2012-2017 Edgewall Software