Show More
@@ -42,6 +42,7 b' 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 | |||
@@ -243,18 +244,21 b' def unescape(st):' | |||||
243 | '\\n' |
|
244 | '\\n' | |
244 | >>> unescape(r'\\\\n') |
|
245 | >>> unescape(r'\\\\n') | |
245 | '\\\\n' |
|
246 | '\\\\n' | |
|
247 | >>> unescape(r'\\\\n\\n') | |||
|
248 | '\\\\n\\n' | |||
246 | """ |
|
249 | """ | |
247 | raw_strings = [ |
|
250 | def unescape_repl(m): | |
248 | (r'\\n', r'\n', '\n'), |
|
251 | m = m.group(1) | |
249 | (r'\\r', r'\r', '\r'), |
|
252 | if m == 'n': | |
250 | (r'\\t', r'\t', '\t'), |
|
253 | return '\n' | |
251 | ] |
|
254 | if m == 't': | |
252 | for a, b, c in raw_strings: |
|
255 | return '\t' | |
253 |
if |
|
256 | if m == 'r': | |
254 | st = st.replace(a, b) |
|
257 | return '\r' | |
255 | else: |
|
258 | if m == '\\': | |
256 | st = st.replace(b, c) |
|
259 | return '\\' | |
257 | return st.replace(r'\"', '"').replace(r'\\', '\\') |
|
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 {{{ |
General Comments 0
You need to be logged in to leave comments.
Login now