def __init__(self, file_obj, orig_filename=None):
self.file_obj = BytesIO(file_obj)
self.orig_filename = orig_filename
if self.orig_filename:
self.final_filename = self.orig_filename
else:
self.final_filename = 'unknownfile.bin'
self.log_details = {'origFilename': self.orig_filename}
self.log_string = ''
if self.orig_filename:
a, self.extension = os.path.splitext(self.orig_filename)
else:
self.extension = None
try:
mt = magic.from_buffer(self.file_obj.getvalue(), mime=True)
except UnicodeEncodeError as e:
# FIXME: The encoding of the file is broken (possibly UTF-16)
mt = ''
self.log_details.update({'UnicodeError': e})
try:
self.mimetype = mt.decode("utf-8")
except:
self.mimetype = mt
if self.mimetype and '/' in self.mimetype:
self.main_type, self.sub_type = self.mimetype.split('/')
else:
self.main_type = ''
self.sub_type = ''
评论列表
文章目录