[plug] MIME Types by file contents
Bernd Felsche
bernie at innovative.iinet.net.au
Fri Jul 2 00:25:26 WST 2004
On Thursday 01 July 2004 14:48, Craig Ringer wrote:
> Bernd Felsche wrote:
> If all you're worried about is PDFs, then:
>
> def ispdf(filepath):
> return file(filepath).read(4) == '%PDF'
>
> should do the trick nicely. It's not hard to generalise that to handle
> any other format kind enough to use magic numbers or header codes.
The Linux/Unix "file" command already does that so to save
re-implementing it as a whole, I've cobbled together the attached
Python function and test program.
The list returned by the function contains not only a maintype and
subtype, but also stuff that might lend itself to smarter encoding
overall... but I'm not too fussed right now.
--
/"\ Bernd Felsche - Innovative Reckoning, Perth, Western Australia
\ / ASCII ribbon campaign | I'm a .signature virus!
X against HTML mail | Copy me into your ~/.signature
/ \ and postings | to help me spread!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mtype.py
Type: text/x-python
Size: 737 bytes
Desc: not available
URL: <http://lists.plug.org.au/pipermail/plug/attachments/20040702/a3f45101/attachment.py>
More information about the plug
mailing list