本文整理匯總了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