def __mimetype(self, path):
"""Detect mimetype of file"""
mime = mimetypes.guess_type(path)[0] or 'unknown'
ext = path[path.rfind('.') + 1:]
if mime == 'unknown' and ('.' + ext) in mimetypes.types_map:
mime = mimetypes.types_map['.' + ext]
if mime == 'text/plain' and ext == 'pl':
mime = self._mimeType[ext]
if mime == 'application/vnd.ms-office' and ext == 'doc':
mime = self._mimeType[ext]
if mime == 'unknown':
if os.path.basename(path) in ['README', 'ChangeLog']:
mime = 'text/plain'
else:
if ext in self._mimeType:
mime = self._mimeType[ext]
# self.__debug('mime ' + os.path.basename(path), ext + ' ' + mime)
return mime
评论列表
文章目录