def decodeFileName(self, name):
# http://code.google.com/p/googleappengine/issues/detail?id=2749
# Open since Sept. 2010, claimed to be fixed in Version 1.7.2 (September 18, 2012)
# and still totally broken
try:
if name.startswith("=?"): #RFC 2047
return unicode( email.Header.make_header(email.Header.decode_header(name + "\n")))
elif "=" in name and not name.endswith("="): #Quoted Printable
return decodestring(name.encode("ascii")).decode("UTF-8")
else: #Maybe base64 encoded
return b64decode(name.encode("ascii")).decode("UTF-8")
except: #Sorry - I cant guess whats happend here
if isinstance(name, str) and not isinstance(name, unicode):
try:
return name.decode("UTF-8", "ignore")
except:
pass
return name
评论列表
文章目录