[Checkins] SVN: z3c.filetype/trunk/ - added a mime.types file for additional file extensions for pythons

Juergen Kartnaller juergen at kartnaller.at
Mon Apr 20 02:25:10 EDT 2009


Log message for revision 99302:
   - added a mime.types file for additional file extensions for pythons
     mimetypes module.
   - added interface for WMA-Audio
     Note : with the current magic.mimes file it is not possible to detect WMA
            files. All WMA files are detected as video/x-ms-asf.
            api.getInterfacesFor(filename='xxx.wma') can be used to detect files
            with extension "wma" as audio/x-ms-wma.
  

Changed:
  U   z3c.filetype/trunk/CHANGES.txt
  U   z3c.filetype/trunk/setup.py
  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/interfaces/__init__.py
  U   z3c.filetype/trunk/src/z3c/filetype/interfaces/filetypes.py
  A   z3c.filetype/trunk/src/z3c/filetype/mime.types

-=-
Modified: z3c.filetype/trunk/CHANGES.txt
===================================================================
--- z3c.filetype/trunk/CHANGES.txt	2009-04-19 22:03:25 UTC (rev 99301)
+++ z3c.filetype/trunk/CHANGES.txt	2009-04-20 06:25:10 UTC (rev 99302)
@@ -5,6 +5,17 @@
 After
 =====
 
+2009/04/20 1.2.1
+================
+
+ - added a mime.types file for additional file extensions for pythons
+   mimetypes module.
+ - added interface for WMA-Audio
+   Note : with the current magic.mimes file it is not possible to detect WMA
+          files. All WMA files are detected as video/x-ms-asf.
+          api.getInterfacesFor(filename='xxx.wma') can be used to detect files
+          with extension "wma" as audio/x-ms-wma.
+
 2009/01/19 1.2.0
 ================
 

Modified: z3c.filetype/trunk/setup.py
===================================================================
--- z3c.filetype/trunk/setup.py	2009-04-19 22:03:25 UTC (rev 99301)
+++ z3c.filetype/trunk/setup.py	2009-04-20 06:25:10 UTC (rev 99302)
@@ -20,7 +20,7 @@
 
 setup(
     name="z3c.filetype",
-    version="1.2.0",
+    version="1.2.1",
     namespace_packages=["z3c"],
     packages=find_packages("src"),
     package_dir={"": "src"},

Modified: z3c.filetype/trunk/src/z3c/filetype/README.txt
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/README.txt	2009-04-19 22:03:25 UTC (rev 99301)
+++ z3c.filetype/trunk/src/z3c/filetype/README.txt	2009-04-20 06:25:10 UTC (rev 99302)
@@ -91,7 +91,17 @@
   word.doc
   [<InterfaceClass z3c.filetype.interfaces.filetypes.IMSWordFile>]
 
+WMA files are alway detected as video/x-ms-asf. The only way is to use the
+file extension. To be able to detect WMA file this package adds its own
+mime.types file to the python mimetypes module.
 
+  >>> import mimetypes
+  >>> mimetypes.knownfiles
+  [... '.../z3c.filetype/src/z3c/filetype/mime.types'...
+
+  >>> sorted(api.getInterfacesFor(filename='test.wma'))
+  [<InterfaceClass z3c.filetype.interfaces.filetypes.IWMAFile>]
+
 The filename is only used if no interface is found, because we should
 not trust the filename in most cases.
 

Modified: z3c.filetype/trunk/src/z3c/filetype/api.py
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/api.py	2009-04-19 22:03:25 UTC (rev 99301)
+++ z3c.filetype/trunk/src/z3c/filetype/api.py	2009-04-20 06:25:10 UTC (rev 99302)
@@ -1,7 +1,8 @@
+import os.path
 from z3c.filetype import magic
 import interfaces
 from interfaces import filetypes
-from zope.contenttype import guess_content_type
+from zope.contenttype import guess_content_type, add_files
 from zope import interface, component
 from zope.lifecycleevent.interfaces import IObjectModifiedEvent
 from zope.lifecycleevent.interfaces import IObjectCreatedEvent
@@ -118,3 +119,8 @@
 def handleCreated(typeableFile, event):
     """handles modification of data"""
     applyInterfaces(typeableFile)
+
+# add our mimetypes definitions to pythons mimetypes module
+here = os.path.dirname(os.path.abspath(__file__))
+add_files([os.path.join(here, "mime.types")])
+

Modified: z3c.filetype/trunk/src/z3c/filetype/interfaces/__init__.py
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/interfaces/__init__.py	2009-04-19 22:03:25 UTC (rev 99301)
+++ z3c.filetype/trunk/src/z3c/filetype/interfaces/__init__.py	2009-04-20 06:25:10 UTC (rev 99302)
@@ -14,5 +14,4 @@
     """A file object that is typeable"""
 
     data = interface.Attribute('Data of the file')
-    
-    
+

Modified: z3c.filetype/trunk/src/z3c/filetype/interfaces/filetypes.py
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/interfaces/filetypes.py	2009-04-19 22:03:25 UTC (rev 99301)
+++ z3c.filetype/trunk/src/z3c/filetype/interfaces/filetypes.py	2009-04-20 06:25:10 UTC (rev 99302)
@@ -109,6 +109,11 @@
 IAudioMPEGFile.setTaggedValue(MTM,re.compile('audio/mpeg'))
 IAudioMPEGFile.setTaggedValue(MT,'audio/mpeg')
 
+class IWMAFile(IAudioFile, IBinaryFile):
+    """Windows Media File Format"""
+    interface.taggedValue(MTM,re.compile('audio/x-ms-wma'))
+    interface.taggedValue(MT,'audio/x-ms-wma')
+
 class IHTMLFile(ITextFile):
     """HTML file"""
 IHTMLFile.setTaggedValue(MTM,re.compile('text/html'))

Added: z3c.filetype/trunk/src/z3c/filetype/mime.types
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/mime.types	                        (rev 0)
+++ z3c.filetype/trunk/src/z3c/filetype/mime.types	2009-04-20 06:25:10 UTC (rev 99302)
@@ -0,0 +1 @@
+audio/x-ms-wma   wma



More information about the Checkins mailing list