Permalink
Browse files

fix mime detection for Fedora python-mime

  • Loading branch information...
1 parent 70bb3dc commit f231185b5baa440d2260879c6529ee23fd02651c @mdomsch committed Jul 17, 2012
Showing with 15 additions and 5 deletions.
  1. +15 −5 S3/S3.py
View
20 S3/S3.py
@@ -39,11 +39,21 @@ def mime_magic_buffer(buffer):
return magic_.from_buffer(buffer)
except TypeError:
## http://pypi.python.org/pypi/filemagic
- magic_ = magic.Magic(flags=magic.MAGIC_MIME)
- def mime_magic_file(file):
- return magic_.id_filename(file)
- def mime_magic_buffer(buffer):
- return magic_.id_buffer(buffer)
+ try:
+ magic_ = magic.Magic(flags=magic.MAGIC_MIME)
+ def mime_magic_file(file):
+ return magic_.id_filename(file)
+ def mime_magic_buffer(buffer):
+ return magic_.id_buffer(buffer)
+ except TypeError:
+ ## file-5.11 built-in python bindings
+ magic_ = magic.open(magic.MAGIC_MIME)
+ magic_.load()
+ def mime_magic_file(file):
+ return magic_.file(file)
+ def mime_magic_buffer(buffer):
+ return magic_.buffer(buffer)
+
except AttributeError:
## Older python-magic versions
magic_ = magic.open(magic.MAGIC_MIME)

0 comments on commit f231185

Please sign in to comment.