pazz/alot — pull request #588 by foobacca (2013-04-02 21:38:49+00:00)
Title: Magic versions

When I try to add a signature using alot, I get the following error

DEBUG:globals:has signature
DEBUG:globals:is file
ERROR:ui:Traceback (most recent call last):
File "/home/hamish/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/twisted/internet/defer.py", line 576, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File "/home/hamish/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/alot/ui.py", line 609, in call_apply
return defer.maybeDeferred(cmd.apply, self)
File "/home/hamish/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/twisted/internet/defer.py", line 138, in maybeDeferred
result = f(*args, **kw)
File "/home/hamish/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/twisted/internet/defer.py", line 1214, in unwindGenerator
return _inlineCallbacks(None, gen, Deferred())
--- ---
File "/home/hamish/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/twisted/internet/defer.py", line 1071, in _inlineCallbacks
result = g.send(result)
File "/home/hamish/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/alot/commands/globals.py", line 726, in apply
enc = helper.guess_encoding(sigcontent)
File "/home/hamish/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/alot/helper.py", line 396, in guess_encoding
m = magic.open(magic.MAGIC_MIME_ENCODING)
exceptions.AttributeError: 'module' object has no attribute 'open'

Two answers on [this stackoverflow question](http://stackoverflow.com/questions/43580/how-to-find-the-mime-type-of-a-file-in-python) suggest that the API had changed by 2010. The current Ubuntu release package installed via apt still has the older version though (with `magic.open`)

I have installed python-magic using pip, and it doesn't seem to want to offer me anything older than 0.4.3 (Unless I have installed entirely the wrong package from pip? I have spent a while looking at various magic file python libraries and haven't found a better one yet.)

This patch checks if magic has the open attribute, and if not it will use the newer version of the magic bindings.