Skip to content

Commit

Permalink
fix: package
Browse files Browse the repository at this point in the history
  • Loading branch information
h2non committed Jun 20, 2016
1 parent db02c8d commit 745173e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Small and dependency free [Python](http://python.org) package to infer file type and MIME type checking the [magic numbers](https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) signature of a file or buffer.

This is a Python port from [filetype](https://github.com/h2non/) Go package.
Works on Python `+3`.
Works in Python `+3`.

## Features

Expand Down
2 changes: 1 addition & 1 deletion filetype/filetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
types = types


def guess_type(obj):
def guess(obj):
"""
Infers the type of the given input.
Expand Down
25 changes: 13 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

try:
from setuptools import setup
except ImportError:
from distutils.core import setup
from setuptools import setup, find_packages
# To use a consistent encoding
from codecs import open
from os import path

description = '''
Infer file type and MIME type of any file/buffer.
No libmagic dependency.
'''

# Get the long description from the README file
here = path.abspath(path.dirname(__file__))
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()

config = {
'name': 'filetype',
'description': description,
'long_description': long_description,
'author': 'Tomas Aparicio',
'author_email': 'tomas@aparicio.me',
'url': 'https://github.com/h2non/filetype.py',
'download_url': 'https://github.com/h2non/filetype.py/tarball/master',
'author_email': 'tomas@aparicio.me',
'version': '0.1.0',
'packages': ['filetype', 'filetype.types'],
'scripts': [],
'license': 'MIT',
'packages': find_packages(exclude=['dist', 'build', 'docs', 'tests']),
'package_data': {
'filetype': ['LICENSE', '*.md'],
},
'entry_points': {
# 'console_scripts': [
# 'filetype = filetype.cmd:run',
# ],
},
'keywords': [
'file',
'libmagic',
Expand Down
14 changes: 7 additions & 7 deletions tests/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@


def test_infer_image_from_disk(benchmark):
benchmark(filetype.guess_type, FIXTURES + '/sample.jpg')
benchmark(filetype.guess, FIXTURES + '/sample.jpg')


def test_infer_video_from_disk(benchmark):
benchmark(filetype.guess_type, FIXTURES + '/sample.mp4')
benchmark(filetype.guess, FIXTURES + '/sample.mp4')


def test_infer_zip_from_disk(benchmark):
benchmark(filetype.guess_type, FIXTURES + '/sample.zip')
benchmark(filetype.guess, FIXTURES + '/sample.zip')


def test_infer_tar_from_disk(benchmark):
benchmark(filetype.guess_type, FIXTURES + '/sample.tar')
benchmark(filetype.guess, FIXTURES + '/sample.tar')


def test_infer_image_from_bytes(benchmark):
benchmark(filetype.guess_type,
benchmark(filetype.guess,
bytearray([0xFF, 0xD8, 0xFF, 0x00, 0x08]))


def test_infer_video_from_bytes(benchmark):
benchmark(filetype.guess_type,
benchmark(filetype.guess,
bytearray([0x1A, 0x45, 0xDF, 0xA3, 0x08]))


def test_infer_audio_from_bytes(benchmark):
benchmark(filetype.guess_type,
benchmark(filetype.guess,
bytearray([0x4D, 0x54, 0x68, 0xA3, 0x64]))
6 changes: 3 additions & 3 deletions tests/test_filetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@

class TestFileType(unittest.TestCase):
def test_guess_file_path(self):
kind = filetype.guess_type(FIXTURES + '/sample.jpg')
kind = filetype.guess(FIXTURES + '/sample.jpg')
self.assertTrue(kind is not None)
self.assertEqual(kind.mime, 'image/jpeg')
self.assertEqual(kind.extension, 'jpg')

def test_guess_buffer(self):
buf = bytearray([0xFF, 0xD8, 0xFF, 0x00, 0x08])
kind = filetype.guess_type(buf)
kind = filetype.guess(buf)
self.assertTrue(kind is not None)
self.assertEqual(kind.mime, 'image/jpeg')
self.assertEqual(kind.extension, 'jpg')

def test_guess_buffer_invalid(self):
buf = bytearray([0xFF, 0x00, 0x00, 0x00, 0x00])
kind = filetype.guess_type(buf)
kind = filetype.guess(buf)
self.assertTrue(kind is None)


Expand Down

0 comments on commit 745173e

Please sign in to comment.