Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b0a13be

Browse files
committed
Just a little refactoring
1 parent e4ee4f9 commit b0a13be

1 file changed

Lines changed: 5 additions & 30 deletions

File tree

thirdparty/magic/magic.py

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""
22
magic is a wrapper around the libmagic file identification library.
33
4-
See README for more information.
5-
64
Usage:
75
86
>>> import magic
@@ -14,7 +12,6 @@
1412
'PDF document, version 1.2'
1513
>>>
1614
17-
1815
"""
1916

2017
import sys
@@ -24,12 +21,12 @@
2421

2522
from ctypes import c_char_p, c_int, c_size_t, c_void_p
2623

27-
class MagicException(Exception): pass
24+
class MagicException(Exception):
25+
pass
2826

2927
class Magic:
3028
"""
3129
Magic is a wrapper around the libmagic C library.
32-
3330
"""
3431

3532
def __init__(self, mime=False, magic_file=None, mime_encoding=False):
@@ -39,8 +36,8 @@ def __init__(self, mime=False, magic_file=None, mime_encoding=False):
3936
mime - if True, mimetypes are returned instead of textual descriptions
4037
mime_encoding - if True, codec is returned
4138
magic_file - use a mime database other than the system default
42-
4339
"""
40+
4441
flags = MAGIC_NONE
4542
if mime:
4643
flags |= MAGIC_MIME
@@ -56,6 +53,7 @@ def from_buffer(self, buf):
5653
"""
5754
Identify the contents of `buf`
5855
"""
56+
5957
return magic_buffer(self.cookie, buf)
6058

6159
def from_file(self, filename):
@@ -104,8 +102,6 @@ def from_buffer(buffer, mime=False):
104102
m = _get_magic_type(mime)
105103
return m.from_buffer(buffer)
106104

107-
108-
109105
try:
110106
libmagic = None
111107
# Let's try to find magic or magic1
@@ -178,7 +174,6 @@ def magic_file(cookie, filename):
178174
def magic_buffer(cookie, buf):
179175
return _magic_buffer(cookie, buf, len(buf))
180176

181-
182177
_magic_load = libmagic.magic_load
183178
_magic_load.restype = c_int
184179
_magic_load.argtypes = [magic_t, c_char_p]
@@ -198,48 +193,28 @@ def magic_load(cookie, filename):
198193
magic_compile = libmagic.magic_compile
199194
magic_compile.restype = c_int
200195
magic_compile.argtypes = [magic_t, c_char_p]
196+
201197
except ImportError:
202198
pass
203199

204-
205200
MAGIC_NONE = 0x000000 # No flags
206-
207201
MAGIC_DEBUG = 0x000001 # Turn on debugging
208-
209202
MAGIC_SYMLINK = 0x000002 # Follow symlinks
210-
211203
MAGIC_COMPRESS = 0x000004 # Check inside compressed files
212-
213204
MAGIC_DEVICES = 0x000008 # Look at the contents of devices
214-
215205
MAGIC_MIME = 0x000010 # Return a mime string
216-
217206
MAGIC_MIME_ENCODING = 0x000400 # Return the MIME encoding
218-
219207
MAGIC_CONTINUE = 0x000020 # Return all matches
220-
221208
MAGIC_CHECK = 0x000040 # Print warnings to stderr
222-
223209
MAGIC_PRESERVE_ATIME = 0x000080 # Restore access time on exit
224-
225210
MAGIC_RAW = 0x000100 # Don't translate unprintable chars
226-
227211
MAGIC_ERROR = 0x000200 # Handle ENOENT etc as real errors
228-
229212
MAGIC_NO_CHECK_COMPRESS = 0x001000 # Don't check for compressed files
230-
231213
MAGIC_NO_CHECK_TAR = 0x002000 # Don't check for tar files
232-
233214
MAGIC_NO_CHECK_SOFT = 0x004000 # Don't check magic entries
234-
235215
MAGIC_NO_CHECK_APPTYPE = 0x008000 # Don't check application type
236-
237216
MAGIC_NO_CHECK_ELF = 0x010000 # Don't check for elf details
238-
239217
MAGIC_NO_CHECK_ASCII = 0x020000 # Don't check for ascii files
240-
241218
MAGIC_NO_CHECK_TROFF = 0x040000 # Don't check ascii/troff
242-
243219
MAGIC_NO_CHECK_FORTRAN = 0x080000 # Don't check ascii/fortran
244-
245220
MAGIC_NO_CHECK_TOKENS = 0x100000 # Don't check ascii/tokens

0 commit comments

Comments
 (0)