summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Hupp <adam@hupp.org>2016-06-05 15:28:20 -0700
committerAdam Hupp <adam@hupp.org>2016-06-05 15:28:44 -0700
commitf82dc97ab906e2e83a26085834fa5fe7696972e8 (patch)
treee5b445c7c1bcbdf55b91b404f2ccd19a74260ff8
parentc64acb4f8c21bf47ca98f9dce42217154b485f2f (diff)
downloadpython-magic-f82dc97ab906e2e83a26085834fa5fe7696972e8.tar.gz
propagate exception in other branch of 509 hack
-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()