equal
deleted
inserted
replaced
40 |
40 |
41 import codecs |
41 import codecs |
42 import struct |
42 import struct |
43 import textwrap |
43 import textwrap |
44 import types |
44 import types |
|
45 import re |
45 |
46 |
46 default_encoding = 'utf-8' |
47 default_encoding = 'utf-8' |
47 |
48 |
48 # function pofile() {{{ |
49 # function pofile() {{{ |
49 |
50 |
241 '\\t and \\n and \\r and " and \\\\' |
242 '\\t and \\n and \\r and " and \\\\' |
242 >>> unescape(r'\\n') |
243 >>> unescape(r'\\n') |
243 '\\n' |
244 '\\n' |
244 >>> unescape(r'\\\\n') |
245 >>> unescape(r'\\\\n') |
245 '\\\\n' |
246 '\\\\n' |
246 """ |
247 >>> unescape(r'\\\\n\\n') |
247 raw_strings = [ |
248 '\\\\n\\n' |
248 (r'\\n', r'\n', '\n'), |
249 """ |
249 (r'\\r', r'\r', '\r'), |
250 def unescape_repl(m): |
250 (r'\\t', r'\t', '\t'), |
251 m = m.group(1) |
251 ] |
252 if m == 'n': |
252 for a, b, c in raw_strings: |
253 return '\n' |
253 if a in st: |
254 if m == 't': |
254 st = st.replace(a, b) |
255 return '\t' |
255 else: |
256 if m == 'r': |
256 st = st.replace(b, c) |
257 return '\r' |
257 return st.replace(r'\"', '"').replace(r'\\', '\\') |
258 if m == '\\': |
|
259 return '\\' |
|
260 return m # handles escaped double quote |
|
261 return re.sub(r'\\(\\|n|t|r|")', unescape_repl, st) |
258 |
262 |
259 # }}} |
263 # }}} |
260 # class _BaseFile {{{ |
264 # class _BaseFile {{{ |
261 |
265 |
262 class _BaseFile(list): |
266 class _BaseFile(list): |