當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。