RES: RFC822Marshaller for all content uploadedwith FTP/Webdav
"Sidnei da Silva" <sidnei-/awGbKECNgO/3pe1ocb+swC/[email protected]> Mon, 22 May 2006 15:26:24 -0500
| Newsgroups | gmane.comp.web.zope.plone.archetypes.devel |
|---|---|
| Message-ID | <[email protected]> |
The mimetypes registry has a copy of magic.py that will look at the contents of a file using the 'magic' identifiers. -- Sidnei da Silva Enfold Systems http://enfoldsystems.com Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214 ________________________________ De: Roché Compaan [mailto:roche-kb4xc5yObU3kQYj/0HfcvhBnub05S5/[email protected]] Enviada: seg 22/5/2006 16:07 Para: Sidnei da Silva Cc: archetypes-devel Assunto: Re: [Archetypes-devel] RFC822Marshaller for all content uploadedwith FTP/Webdav On Tue, 2006-05-02 at 14:50 -0300, Sidnei da Silva wrote: > On Tue, May 02, 2006 at 07:35:16PM +0200, Roché Compaan wrote: > | I won't have time to write a PLIP and I need to fix this for the client > | now. I'd like to fix this in a way that might be usable by you. I didn't have time to work on this until now. > | I am hoping for an implementation that is a bit more intelligent as > | opposed to just having good defaults. IMO a very simple fix would be to > | not try to demarshall a file using RFC822Marshaller if it is not > | appropriate. Maybe even better would be to have an über marshaller that > | uses RFC882 when appropriate and upload files that are clearly not > | RFC822 compliant as files, not Plone documents. > > That is exactly what I have in mind. One small issue is that we must > *not* read the whole file in memory. Usually reading a small chunk of > the file should be enough to detect which marshaller should be > used. This should optimally use the Marshall product to make these > settings overridable TTW. I can't find any Python library that guesses file types based on the *content* of the file. There is the 'file' command on linux but I don't consider this an option since it is probably not available on windows. What the 'file' command does give me is the strings from the 'magic' file and this can easily be used to test for known file types. >From "man magic": "Each line of the file specifies a test to be performed. A test compares the data starting at a particular offset in the file with a 1-byte, 2-byte, or 4-byte numeric value or a string. If the test succeeds, a message is printed." This is the most solid ground for matching file types on their content I have found. Any other ideas or recommendations? -- Roché Compaan Upfront Systems http://www.upfrontsystems.co.za