def __str_quote(string):
if type(string).__name__ == "str":
try:
string = unicode(string, encoding='utf-8', errors='xmlcharrefreplace')
except TypeError:
string = unicode(string, encoding='utf-8', errors='ignore')
elif type(string).__name__ == "unicode":
try:
string = string.encode(encoding='utf-8', errors='xmlcharrefreplace')
except UnicodeEncodeError:
string = string.encode(encoding='utf-8', errors='ignore')
string = pattern.sub(lambda m: rep[re.escape(m.group(0))], string)
try:
return quote(string, safe='')
except KeyError:
print "QUOTE FAIL"
print type(string).__name__
print string
exit()
评论列表
文章目录