blob: 40dce60f7a3f65485e71d735c9f2187fe969d858 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
= python-magic =
Adam Hupp <adam at hupp.org>
Distributed under the PSF License: http://www.python.org/psf/license/
python-magic is a simple wrapper for libmagic. libmagic identifies
file types according to their headers. It is the core of the Unix
"file" command.
= Installation =
To build and install run:
# python setup.py install
= Installation on Win32 =
You need magic1.dll from http://gnuwin32.sourceforge.net/, grab the
binaries and dependencies ZIP-file, extract magic1.dll, regex2.dll
and zlib1.dll and put it in C:\Windows\System32. You also need a
magic file from Linux, compatible with file version 5.0.
To build and install run:
# python setup.py install
= Example Usage =
>>> import magic
>>> m = magic.Magic()
>>> m.from_file("testdata/test.pdf")
'PDF document, version 1.2'
>>> m.from_buffer(open("testdata/test.pdf").read(1024))
'PDF document, version 1.2'
# For MIME types
>>> mime = magic.Magic(mime=True)
>>> mime.from_file("testdata/test.pdf")
'application/pdf'
>>>
# For MIME encoding
>>> mime_encoding = magic.Magic(mime_encoding=True)
>>> mime_encoding.from_file("testdata/text-iso8859-1.txt")
'iso-8859-1'
>>>
= Contributors =
Thanks to these folks on github who submitted features and bugfixes.
NicolasDelaby
lukenowak
FlaPer87
SimpleSeb
tehmaze
sacha@ssl.co.uk
|