[Python-ideas] os.path.isbinary
Andrew Barnert
abarnert at yahoo.com
Thu Aug 1 06:07:51 CEST 2013
From: Ryan <rymg19 at gmail.com>
Sent: Wednesday, July 31, 2013 7:45 PM
>What about something like this:
>
>https://github.com/ahupp/python-magic
That particular wrapper is just a ctypes wrapper libmagic.so/.dylib, and not a very portable one (e.g., it's got the path /usr/local/Cellar/libmagic/5.10/ hardcoded into it… which will only work for Mac Homebrew users who are 4 versions/19 months out of date…). Also, note that libmagic already comes with very similar Python ctypes-based bindings.
However, there are a half-dozen other wrappers around libmagic on PyPI, and it's pretty trivial to create a new one. The tricky bit is where to get the libmagic code and data files from. If you want to make it usable on most platforms, you'd need to add the file source distribution to the Python source, build it with Python, and statically link it into a module, ala zlib or sqlite. And, unlike those modules, you'd also need to include a data file (magic.mgc) with the binary distribution.
I slapped together a quick&dirty wrapper to see what the costs are. It adds 640KB to the 14MB source distribution, 300KB to the 91MB binary (64-bit Mac framework build), and under 10 seconds to the build process. There'd be a bit of an extra maintenance burden in tracking updates (the most recent two updates were 21 Mar 2013 and 22 Feb 2013). The code and data are BSD-licensed, which shouldn't be a problem. The library is very portable: "./configure --enable-static; make" worked even on Windows.
So, is it worth adding to Python? I don't know. But it seems at least feasible.
More information about the Python-ideas
mailing list