Python mimetypes.knownfiles() Examples

The following are 5 code examples of mimetypes.knownfiles(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module mimetypes , or try the search function .
Example #1
Source File: stubs_test.py    From browserscope with Apache License 2.0 5 votes vote down vote up
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)) 
Example #2
Source File: test_oidc.py    From ga4gh-server with Apache License 2.0 5 votes vote down vote up
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") 
Example #3
Source File: __init__.py    From scylla with Apache License 2.0 5 votes vote down vote up
def find_mimetypes():
    import mimetypes
    for name in mimetypes.knownfiles:
        if os.path.exists(name):
            return name
            break
    else:
        return '/dev/null' 
Example #4
Source File: stubs_test.py    From python-compat-runtime with Apache License 2.0 5 votes vote down vote up
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)) 
Example #5
Source File: DownloadImpl.py    From p2ptv-pi with MIT License 4 votes vote down vote up
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