handle utf-8 in unrepr
This commit is contained in:
parent
8d0479e976
commit
e3236bdfa8
|
@ -361,6 +361,7 @@ Please specify account for sending the message.') % sys.argv[2])
|
||||||
return ('',value[1:])
|
return ('',value[1:])
|
||||||
_str = ''
|
_str = ''
|
||||||
previous_slash = False
|
previous_slash = False
|
||||||
|
slashes = 0
|
||||||
for i in range(len(value) - 1):
|
for i in range(len(value) - 1):
|
||||||
chr = value[i+1]
|
chr = value[i+1]
|
||||||
if previous_slash:
|
if previous_slash:
|
||||||
|
@ -379,15 +380,19 @@ Please specify account for sending the message.') % sys.argv[2])
|
||||||
_str += '\''
|
_str += '\''
|
||||||
elif chr == '\"':
|
elif chr == '\"':
|
||||||
_str += '\"'
|
_str += '\"'
|
||||||
elif chr == 'u' and is_unicode:
|
elif chr in ['u', 'x'] and is_unicode:
|
||||||
_str += '\\u'
|
slashes -= 1
|
||||||
|
_str += '\\' + chr
|
||||||
|
else:
|
||||||
|
_str += chr
|
||||||
elif chr == first_char:
|
elif chr == first_char:
|
||||||
break
|
break
|
||||||
elif chr == '\\':
|
elif chr == '\\':
|
||||||
previous_slash = True
|
previous_slash = True
|
||||||
|
slashes += 1
|
||||||
else:
|
else:
|
||||||
_str += chr
|
_str += chr
|
||||||
substr_len = len(_str)+2
|
substr_len = len(_str) + 2 + slashes
|
||||||
if is_unicode and _str:
|
if is_unicode and _str:
|
||||||
_str = _str.decode('unicode-escape').encode('utf-8')
|
_str = _str.decode('unicode-escape').encode('utf-8')
|
||||||
return (_str, value[substr_len :])
|
return (_str, value[substr_len :])
|
||||||
|
|
Loading…
Reference in New Issue