[plug] MIME Types by file contents
Bernd Felsche
bernie at innovative.iinet.net.au
Fri Jul 2 20:55:10 WST 2004
On Friday 02 July 2004 20:30, Craig Ringer wrote:
> On Fri, 2004-07-02 at 00:25, Bernd Felsche wrote:
> > 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.
>
> I'd like to add a comment on that function: your use of a local
> variable called 'file' may bend the brain of some Python users, as
> 'file' is a built-in object that's imported into the __main__
> namespace from __builtin__ automatically. Assigning to that name
> won't affect 'file', it'll just hide it within that function, but
> ... it's really weird to read the code when you're used to writing
>
> fdata = file(path_to_file).read()
Errmm yes. you're right of course. I'll change that.
> and similar.
>
> Also - any chance you can send me some sample output from 'file' that
> exercises the full depth of that nest of for loops? I'm not getting much
> interesting output out of 'file' - the most interesting is from a core
> file - and I'm curious.
Using "file -bi ~/* | sort -u"
application/msword
application/pdf
application/x-empty
application/x-executable, dynamically linked (uses shared libs), not stripped
application/x-gzip
application/x-not-regular-file
application/x-perl
application/x-shellscript
application/x-zip
data
image/gif
image/jpeg
message/news 8bit
text/html
text/html; charset=us-ascii
text/plain, English; charset=iso-8859-1
text/plain, English; charset=us-ascii
text/plain; charset=iso-8859-1
text/plain; charset=us-ascii
text/x-c; charset=us-ascii
text/x-java; charset=us-ascii
text/x-mail; charset=us-ascii
The for loops split on each of ;, and tab.
The most-complex I've encountered are "text/plain, English;
charset=iso-8859-1" and the like.
Note the alternate magic file used when MIME output is required; the
output text will depend on what's in the magic file. I've not run an
exhaustive test on that yet to ensure that it'll generate the
appropriate list in Python.
--
/"\ 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!
More information about the plug
mailing list