def mime(self):
if hasattr(magic, "from_file"):
# Use https://pypi.python.org/pypi/python-magic
return magic.from_file(self.fetch('filename'), mime=True)
elif hasattr(magic, "open"):
# Use the python-magic library in distro repos from the `file`
# command - http://www.darwinsys.com/file/
magic_instance = magic.open(magic.MAGIC_MIME)
magic_instance.load()
return magic_instance.file(self.fetch('filename'))
raise ImportError(
'The `magic` module that was found is not the expected pypi '
'package python-magic (https://pypi.python.org/pypi/python-magic) '
'nor file\'s (http://www.darwinsys.com/file/) package.')
评论列表
文章目录