How to use the filetype.guess_mime function in filetype

To help you get started, we’ve selected a few filetype examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github h2non / filetype.py / tests / test_filetype.py View on Github external
def test_guess_mime_file_path(self):
        mime = filetype.guess_mime(FIXTURES + '/sample.jpg')
        self.assertTrue(mime is not None)
        self.assertEqual(mime, 'image/jpeg')
github h2non / filetype.py / tests / test_filetype.py View on Github external
def test_guess_mime_buffer(self):
        buf = bytearray([0xFF, 0xD8, 0xFF, 0x00, 0x08])
        mime = filetype.guess_mime(buf)
        self.assertTrue(mime is not None)
        self.assertEqual(mime, 'image/jpeg')
github h2non / filetype.py / tests / test_filetype.py View on Github external
def test_guess_mime_memoryview(self):
        buf = memoryview(bytearray([0xFF, 0xD8, 0xFF, 0x00, 0x08]))
        mime = filetype.guess_mime(buf)
        self.assertTrue(mime is not None)
        self.assertEqual(mime, 'image/jpeg')
github h2non / filetype.py / tests / test_filetype.py View on Github external
def test_guess_mime_buffer_invalid(self):
        buf = bytearray([0xFF, 0x00, 0x00, 0x00, 0x00])
        mime = filetype.guess_mime(buf)
        self.assertTrue(mime is None)
github nicfit / eyeD3 / eyed3 / mimetype.py View on Github external
data = data.lstrip(b"\x00")
            if data:
                data_len = len(data)
                if data_len >= _NUM_SIGNATURE_BYTES:
                    buf = data[:_NUM_SIGNATURE_BYTES]
                else:
                    buf = data + signature.read(_NUM_SIGNATURE_BYTES - data_len)

        # Special casing .id3/.tag because extended filetype with add_type() prepends, meaning
        # all mp3 would be labeled mimetype id3, while appending would mean each .id3 would be
        # mime mpeg.
        if path.suffix in ID3_MIME_TYPE_EXTENSIONS:
            if Id3Tag().match(buf) or Id3TagExt().match(buf):
                return Id3TagExt.MIME

        return filetype.guess_mime(buf)
github pyload / pyload-webui / pyload / utils / path.py View on Github external
@iterate
def filetype(path):
    try:
        return magic.from_file(path, mime=True)
    except NameError:
        pass
    return guess_mime(path)