本文整理汇总了Python中mimetypes.knownfiles方法的典型用法代码示例。如果您正苦于以下问题:Python mimetypes.knownfiles方法的具体用法?Python mimetypes.knownfiles怎么用?Python mimetypes.knownfiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mimetypes
的用法示例。
在下文中一共展示了mimetypes.knownfiles方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_is_accessible_mimetypes_files
# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import knownfiles [as 别名]
def test_is_accessible_mimetypes_files(self):
stubs.FakeFile.set_allowed_paths(self.tempdir, [])
for filename in mimetypes.knownfiles:
if os.path.isfile(filename):
self.assertTrue(stubs.FakeFile.is_file_accessible(filename))
示例2: testMimetype
# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import knownfiles [as 别名]
def testMimetype(self):
"""
The `oidc-provider` relies on mimetypes.guess_type(full_path)
`mimetypes` in turn relies on the host OS configuration,
typically ["/etc/mime.types","/etc/httpd/conf/mime.types",...]
If this test fails, see the results of `mimetypes.knownfiles`
on your host and ensure configuration set up
see https://github.com/ga4gh/ga4gh-server/issues/501
"""
content_type, encoding = mimetypes.guess_type("foo.json")
self.assertEqual(content_type, "application/json")
示例3: find_mimetypes
# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import knownfiles [as 别名]
def find_mimetypes():
import mimetypes
for name in mimetypes.knownfiles:
if os.path.exists(name):
return name
break
else:
return '/dev/null'
示例4: get_mimetype
# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import knownfiles [as 别名]
def get_mimetype(self, file):
prefix, ext = os.path.splitext(file)
ext = ext.lower()
mimetype = None
if sys.platform == 'win32':
try:
from ACEStream.Video.utils import win32_retrieve_video_play_command
mimetype, playcmd = win32_retrieve_video_play_command(ext, file)
if DEBUG:
log(self.log_prefix + 'get_mimetype: Win32 reg said MIME type is', mimetype)
except:
if DEBUG:
log_exc()
else:
try:
import mimetypes
homedir = get_home_dir()
homemapfile = os.path.join(homedir, '.mimetypes')
mapfiles = [homemapfile] + mimetypes.knownfiles
mimetypes.init(mapfiles)
mimetype, encoding = mimetypes.guess_type(file)
if DEBUG:
log(self.log_prefix + 'get_mimetype: /etc/mimetypes+ said MIME type is', mimetype, file)
except:
log_exc()
if mimetype is None:
if ext == '.avi':
mimetype = 'video/avi'
elif ext == '.mpegts' or ext == '.ts':
mimetype = 'video/mp2t'
elif ext == '.mkv':
mimetype = 'video/x-matroska'
elif ext == '.ogg' or ext == '.ogv':
mimetype = 'video/ogg'
elif ext == '.oga':
mimetype = 'audio/ogg'
elif ext == '.webm':
mimetype = 'video/webm'
else:
mimetype = 'video/mpeg'
return mimetype