当前位置: 首页>>代码示例>>Python>>正文


Python mimetypes.knownfiles方法代码示例

本文整理汇总了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)) 
开发者ID:elsigh,项目名称:browserscope,代码行数:7,代码来源:stubs_test.py

示例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") 
开发者ID:ga4gh,项目名称:ga4gh-server,代码行数:13,代码来源:test_oidc.py

示例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' 
开发者ID:acaceres2176,项目名称:scylla,代码行数:10,代码来源:__init__.py

示例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 
开发者ID:alesnav,项目名称:p2ptv-pi,代码行数:45,代码来源:DownloadImpl.py


注:本文中的mimetypes.knownfiles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。