How to use filetype - 10 common examples

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_memoryview(self):
        buf = memoryview(bytearray([0xFF, 0xD8, 0xFF, 0x00, 0x08]))
        kind = filetype.guess(buf)
        self.assertTrue(kind is not None)
        self.assertEqual(kind.mime, 'image/jpeg')
        self.assertEqual(kind.extension, 'jpg')
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 h2non / filetype.py / tests / test_filetype.py View on Github external
def test_guess_extension_buffer_invalid(self):
        buf = bytearray([0xFF, 0x00, 0x00, 0x00, 0x00])
        ext = filetype.guess_extension(buf)
        self.assertTrue(ext is None)
github h2non / filetype.py / tests / test_filetype.py View on Github external
def test_guess_extension_file_path(self):
        ext = filetype.guess_extension(FIXTURES + '/sample.jpg')
        self.assertTrue(ext is not None)
        self.assertEqual(ext, 'jpg')
github h2non / filetype.py / tests / test_filetype.py View on Github external
def test_guess_extension_buffer(self):
        buf = bytearray([0xFF, 0xD8, 0xFF, 0x00, 0x08])
        ext = filetype.guess_extension(buf)
        self.assertTrue(ext is not None)
        self.assertEqual(ext, 'jpg')
github h2non / filetype.py / tests / test_filetype.py View on Github external
def test_guess_extension_memoryview(self):
        buf = memoryview(bytearray([0xFF, 0xD8, 0xFF, 0x00, 0x08]))
        ext = filetype.guess_extension(buf)
        self.assertTrue(ext is not None)
        self.assertEqual(ext, 'jpg')
github eerkunt / terraform-compliance / terraform_compliance / common / readable_plan.py View on Github external
def __call__(self, parser, namespace, values, option_string=None):
        # Check if the given path is a file
        if not os.path.isfile(values):
            print('ERROR: {} is not a file.'.format(values))
            sys.exit(1)

        # Check if the given file is a native terraform plan file
        given_file = filetype.guess(values)

        if given_file is not None:
            terraform_executable = getattr(namespace, 'terraform_file', None)
            values = convert_terraform_plan_to_json(os.path.abspath(values), terraform_executable)

        # Check if the given file is a json file.
        try:
            with open(values, 'r', encoding='utf-8') as plan_file:
                data = json.load(plan_file)

        except json.decoder.JSONDecodeError:
            print('ERROR: {} is not a valid JSON file'.format(values))
            sys.exit(1)
        except UnicodeDecodeError:
            print('ERROR: {} is not a valid JSON file.'.format(values))
            print('       Did you try to convert the binary plan file to json with '