summaryrefslogtreecommitdiff
path: root/magic.py
diff options
context:
space:
mode:
authorNicolas Delaby <nicolas@nicolas-laptop.(none)>2010-10-15 14:20:47 +0200
committerNicolas Delaby <nicolas@nicolas-laptop.(none)>2010-10-15 14:20:47 +0200
commit7354884c26cec98b5b5bb02e54a371da658cf10d (patch)
tree74bead7013dd9769aa895cf05d20938aa57ca00c /magic.py
parent4142c792280cd371462d4bdf53e0a6533dfb5e9f (diff)
downloadpython-magic-7354884c26cec98b5b5bb02e54a371da658cf10d.tar.gz
Add new feature which return mime_encoding of file.
Diffstat (limited to 'magic.py')
-rw-r--r--magic.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/magic.py b/magic.py
index 53e9609..b8c6935 100644
--- a/magic.py
+++ b/magic.py
@@ -31,18 +31,21 @@ class Magic:
"""
- def __init__(self, mime=False, magic_file=None):
+ def __init__(self, mime=False, mime_encoding=False, magic_file=None):
"""
Create a new libmagic wrapper.
mime - if True, mimetypes are returned instead of textual descriptions
+ mime_encoding - if True, codec is returned
magic_file - use a mime database other than the system default
"""
flags = MAGIC_NONE
if mime:
flags |= MAGIC_MIME
-
+ elif mime_encoding:
+ flags |= MAGIC_MIME_ENCODING
+
self.cookie = magic_open(flags)
magic_load(self.cookie, magic_file)
@@ -186,6 +189,8 @@ MAGIC_DEVICES = 0x000008 # Look at the contents of devices
MAGIC_MIME = 0x000010 # Return a mime string
+MAGIC_MIME_ENCODING = 0x000400 # Return the MIME encoding
+
MAGIC_CONTINUE = 0x000020 # Return all matches
MAGIC_CHECK = 0x000040 # Print warnings to stderr