diff options
| author | Adam Hupp <adam@hupp.org> | 2013-10-23 12:21:07 -0700 |
|---|---|---|
| committer | Adam Hupp <adam@hupp.org> | 2013-10-23 12:21:07 -0700 |
| commit | 75eab74a2f43943a45e1b8ba5dd9f733184f0cc8 (patch) | |
| tree | e3b56052854b1c9e4c8540d357d8b1bc2824b46a /magic.py | |
| parent | a051eae3ebc7a5555cb32ca8b99ffb099b5a19da (diff) | |
| download | python-magic-75eab74a2f43943a45e1b8ba5dd9f733184f0cc8.tar.gz | |
Hypothetical fix for issue https://github.com/ahupp/python-magic/issues/47
Diffstat (limited to 'magic.py')
| -rw-r--r-- | magic.py | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -63,7 +63,10 @@ class Magic: Identify the contents of `buf` """ self._thread_check() - return magic_buffer(self.cookie, buf) + try: + return magic_buffer(self.cookie, buf) + except MagicException as e: + return self._handle509Bug(e) def from_file(self, filename): """ @@ -73,8 +76,17 @@ class Magic: self._thread_check() if not os.path.exists(filename): raise IOError("File does not exist: " + filename) - - return magic_file(self.cookie, filename) + try: + return magic_file(self.cookie, filename) + except MagicException as e: + return self._handle509Bug(e) + + def _handle509Bug(self, e): + # libmagic 5.09 has a bug where it might mail to identify the + # mimetype of a file and returns null from magic_file (and + # likely _buffer), but also does not return an error message. + if e.message is None and (self.flags & MAGIC_MIME): + return "application/octet-stream" def _thread_check(self): if self.thread != threading.currentThread(): |
