summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--magic.py4
-rwxr-xr-xtest/test.py11
2 files changed, 14 insertions, 1 deletions
diff --git a/magic.py b/magic.py
index c6142a7..9e5f81f 100644
--- a/magic.py
+++ b/magic.py
@@ -92,7 +92,9 @@ class Magic:
# likely _buffer), but also does not return an error message.
if e.message is None and (self.flags & MAGIC_MIME):
return "application/octet-stream"
-
+ else:
+ raise e
+
def __del__(self):
# no _thread_check here because there can be no other
# references to this object at this point.
diff --git a/test/test.py b/test/test.py
index 03914ff..5eaaa0d 100755
--- a/test/test.py
+++ b/test/test.py
@@ -92,5 +92,16 @@ class MagicTest(unittest.TestCase):
m = magic.Magic(mime=True, keep_going=True)
self.assertEqual(m.from_file(filename), 'image/jpeg'.encode('utf-8'))
+
+ def test_rethrow(self):
+ old = magic.magic_buffer
+ try:
+ def t(x,y):
+ raise magic.MagicException("passthrough")
+ magic.magic_buffer = t
+
+ self.assertRaises(magic.MagicException, magic.from_buffer, "hello", True)
+ finally:
+ magic.magic_buffer = old
if __name__ == '__main__':
unittest.main()