[Checkins] SVN: z3c.filetype/trunk/src/z3c/filetype/ changed magic implementation to return sets, and added quicktime magic numbers

Bernd Dorn bernd.dorn at fhv.at
Mon Aug 14 12:41:23 EDT 2006


Log message for revision 69482:
  changed magic implementation to return sets, and added quicktime magic numbers

Changed:
  U   z3c.filetype/trunk/src/z3c/filetype/README.txt
  U   z3c.filetype/trunk/src/z3c/filetype/api.py
  U   z3c.filetype/trunk/src/z3c/filetype/magic.mime
  U   z3c.filetype/trunk/src/z3c/filetype/magic.py
  U   z3c.filetype/trunk/src/z3c/filetype/magic.txt
  A   z3c.filetype/trunk/src/z3c/filetype/testdata/ftyp.mov

-=-
Modified: z3c.filetype/trunk/src/z3c/filetype/README.txt
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/README.txt	2006-08-14 16:05:46 UTC (rev 69481)
+++ z3c.filetype/trunk/src/z3c/filetype/README.txt	2006-08-14 16:41:23 UTC (rev 69482)
@@ -24,6 +24,8 @@
   ...     print i
   DS_Store
   set([<InterfaceClass z3c.filetype.interfaces.filetypes.IBinaryFile>])
+  ftyp.mov
+  set([<InterfaceClass z3c.filetype.interfaces.filetypes.IVideoFile>])
   jumps.mov
   set([<InterfaceClass z3c.filetype.interfaces.filetypes.IVideoFile>])
   logo.gif

Modified: z3c.filetype/trunk/src/z3c/filetype/api.py
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/api.py	2006-08-14 16:05:46 UTC (rev 69481)
+++ z3c.filetype/trunk/src/z3c/filetype/api.py	2006-08-14 16:41:23 UTC (rev 69482)
@@ -33,8 +33,8 @@
     
     ifaces = set()
     if file is not None:
-        t = magicFile.detect(file)
-        if t is not None:
+        types = magicFile.detect(file)
+        for t in types:
             ifaces.update(byMimeType(t))
     if mimeType is not None:
         ifaces.update(byMimeType(mimeType))

Modified: z3c.filetype/trunk/src/z3c/filetype/magic.mime
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/magic.mime	2006-08-14 16:05:46 UTC (rev 69481)
+++ z3c.filetype/trunk/src/z3c/filetype/magic.mime	2006-08-14 16:41:23 UTC (rev 69482)
@@ -603,8 +603,18 @@
 # SGI and Apple formats
 #
 0	string		MOVI				video/sgi
-4	string		moov				video/quicktime	moov
-4	string		mdat				video/quicktime	mdat
+
+# Apple Quicktime: Scan for all known top-level QT atom markers
+4       string          moov            video/quicktime (moov)
+4       string          mdat            video/quicktime (mdat)
+4       string          ftyp            video/quicktime (ftyp)
+4       string          free            video/quicktime (free)
+4       string          junk            video/quicktime (junk)
+4       string          pnot            video/quicktime (pnot)
+4       string          skip            video/quicktime (skip)
+4       string          wide            video/quicktime (wide)
+4       string          pict            video/quicktime (pict)
+
 # The contributor claims:
 #   I couldn't find a real magic number for these, however, this
 #   -appears- to work.  Note that it might catch other files, too,

Modified: z3c.filetype/trunk/src/z3c/filetype/magic.py
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/magic.py	2006-08-14 16:05:46 UTC (rev 69481)
+++ z3c.filetype/trunk/src/z3c/filetype/magic.py	2006-08-14 16:41:23 UTC (rev 69482)
@@ -494,16 +494,16 @@
     def detect(self,file):
         self.ack_tests = 0
         self.nak_tests = 0
-        answers = []
+        answers = set()
         for test in self.tests :
             message = test.run( file )
             if message :
                 self.ack_tests += 1
-                answers.append( message )
+                answers.add( message.strip().split()[0] )
             else:
                 self.nak_tests += 1
-        if answers :
-            return '; '.join( answers )
+        return answers
+
 #end class MagicFile
 
 def username(uid):

Modified: z3c.filetype/trunk/src/z3c/filetype/magic.txt
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/magic.txt	2006-08-14 16:05:46 UTC (rev 69481)
+++ z3c.filetype/trunk/src/z3c/filetype/magic.txt	2006-08-14 16:41:23 UTC (rev 69482)
@@ -2,7 +2,7 @@
  Magic
 =======
 
-Extract filetype from file content
+Extract filetypes from file content
 
   >>> from z3c.filetype import magic
   >>> import os
@@ -13,17 +13,18 @@
   ...     if name==".svn": continue
   ...     path = os.path.join(testData, name)
   ...     print name, m.detect(file(path))
-  DS_Store None
-  jumps.mov video/quicktime ; video/quicktime 
-  logo.gif image/gif
-  logo.gif.bz2 application/x-bzip2
-  test.flv video/x-flv 
-  test.gnutar application/x-tar ; application/x-tar 
-  test.html text/html 
-  test.png image/png 
-  test.tar application/x-tar ; application/x-tar 
-  test.tgz application/x-gzip 
-  test.txt.gz application/x-gzip 
-  test2.html text/html 
-  test2.thml text/html 
-  thumbnailImage_small.jpeg image/jpeg 
+  DS_Store set([])
+  ftyp.mov set(['video/quicktime'])
+  jumps.mov set(['video/quicktime'])
+  logo.gif set(['image/gif'])
+  logo.gif.bz2 set(['application/x-bzip2'])
+  test.flv set(['video/x-flv'])
+  test.gnutar set(['application/x-tar'])
+  test.html set(['text/html'])
+  test.png set(['image/png'])
+  test.tar set(['application/x-tar'])
+  test.tgz set(['application/x-gzip'])
+  test.txt.gz set(['application/x-gzip'])
+  test2.html set(['text/html'])
+  test2.thml set(['text/html'])
+  thumbnailImage_small.jpeg set(['image/jpeg'])

Added: z3c.filetype/trunk/src/z3c/filetype/testdata/ftyp.mov
===================================================================
(Binary files differ)


Property changes on: z3c.filetype/trunk/src/z3c/filetype/testdata/ftyp.mov
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream



More information about the Checkins mailing list