summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--magic.py4
-rwxr-xr-xtest/test.py15
2 files changed, 14 insertions, 5 deletions
diff --git a/magic.py b/magic.py
index 773e4ae..aab7987 100644
--- a/magic.py
+++ b/magic.py
@@ -70,6 +70,10 @@ class Magic:
magic_load(self.cookie, magic_file)
+ # MAGIC_EXTENSION was added in 523 or 524, so bail if
+ # it doesn't appear to be available
+ if extension and (not _has_version or version() < 524):
+ raise NotImplementedError('MAGIC_EXTENSION is not supported in this version of libmagic')
# For https://github.com/ahupp/python-magic/issues/190
# libmagic has fixed internal limits that some files exceed, causing
diff --git a/test/test.py b/test/test.py
index 15a4115..eb5af89 100755
--- a/test/test.py
+++ b/test/test.py
@@ -112,11 +112,16 @@ class MagicTest(unittest.TestCase):
del os.environ['TZ']
def test_extension(self):
- m = magic.Magic(extension=True)
- self.assert_values(m, {
- 'test.gz': 'gz/tgz/tpz/zabw/svgz',
- 'name_use.jpg': 'jpeg/jpg/jpe/jfif',
- })
+ try:
+ m = magic.Magic(extension=True)
+ self.assert_values(m, {
+ # some versions return '' for the extensions of a gz file,
+ # including w/ the command line. Who knows...
+ 'test.gz': ('gz/tgz/tpz/zabw/svgz', '', '???'),
+ 'name_use.jpg': 'jpeg/jpg/jpe/jfif',
+ })
+ except NotImplementedError:
+ self.skipTest('MAGIC_EXTENSION not supported in this version')
def test_unicode_result_nonraw(self):
m = magic.Magic(raw=False)