[Checkins] SVN: z3c.filetype/trunk/src/z3c/filetype/ added event handler for IObjectModified

Bernd Dorn bernd.dorn at fhv.at
Fri Aug 11 11:38:35 EDT 2006


Log message for revision 69405:
  added event handler for IObjectModified

Changed:
  U   z3c.filetype/trunk/src/z3c/filetype/README.txt
  U   z3c.filetype/trunk/src/z3c/filetype/api.py
  A   z3c.filetype/trunk/src/z3c/filetype/configure.zcml
  U   z3c.filetype/trunk/src/z3c/filetype/event.py
  A   z3c.filetype/trunk/src/z3c/filetype/z3c.filetype-configure.zcml

-=-
Modified: z3c.filetype/trunk/src/z3c/filetype/README.txt
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/README.txt	2006-08-11 14:54:22 UTC (rev 69404)
+++ z3c.filetype/trunk/src/z3c/filetype/README.txt	2006-08-11 15:38:34 UTC (rev 69405)
@@ -104,12 +104,54 @@
   >>> eventtesting.getEvents()
   [<z3c.filetype.event.FileTypeModifiedEvent object at ...>]
 
+A second applyInteraces does nothing.
+
+  >>> eventtesting.clearEvents()
   >>> api.applyInterfaces(foo)
   False
+  >>> eventtesting.getEvents()
+  []
 
 Now the object should implement the right interface according to the
 ata contained.
 
-  >>> interfaces.filetypes.ITARFile.providedBy(foo)
+  >>> sorted((interface.directlyProvidedBy(foo)))
+  [<InterfaceClass z3c.filetype.interfaces.filetypes.ITARFile>]
+
+If we change the object the interface changes too.
+
+  >>> foo.data = file(os.path.join(testData,'test.flv'))
+  >>> api.applyInterfaces(foo)
   True
+  >>> sorted((interface.directlyProvidedBy(foo)))
+  [<InterfaceClass z3c.filetype.interfaces.filetypes.IFLVFile>]
 
+
+There is also an event handler registered on IObjectModified for
+ITypeableFile. We register it here in the test.
+
+  >>> from z3c.filetype.event import handleModified
+  >>> from zope import component
+  >>> component.provideHandler(handleModified)
+  >>> foo.data = file(os.path.join(testData,'test.html'))
+
+So we need to fire an IObjectModifiedevent. Which is normally done by
+the implementation.
+
+  >>> from zope.lifecycleevent import ObjectModifiedEvent
+  >>> from zope.event import notify
+  >>> eventtesting.clearEvents()
+  >>> notify(ObjectModifiedEvent(foo))
+
+Now we have two events, one we fired and one from our handler.
+
+  >>> eventtesting.getEvents()
+  [<zope.app.event.objectevent.ObjectModifiedEvent object at ...>,
+   <z3c.filetype.event.FileTypeModifiedEvent object at ...>]
+  
+Now the file should implement another filetype.
+
+  >>> sorted((interface.directlyProvidedBy(foo)))
+  [<InterfaceClass z3c.filetype.interfaces.filetypes.IHTMLFile>]
+
+

Modified: z3c.filetype/trunk/src/z3c/filetype/api.py
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/api.py	2006-08-11 14:54:22 UTC (rev 69404)
+++ z3c.filetype/trunk/src/z3c/filetype/api.py	2006-08-11 15:38:34 UTC (rev 69405)
@@ -49,7 +49,8 @@
     ifaces = InterfaceSet(*getInterfacesFor(obj.data))
     provided = set(interface.directlyProvidedBy(obj))
     for iface in provided:
-        ifaces.add(iface)
+        if not issubclass(iface, interfaces.filetypes.ITypedFile):
+            ifaces.add(iface)
     if set(ifaces)!=provided:
         for iface in ifaces:
             interface.directlyProvides(obj,iface)

Added: z3c.filetype/trunk/src/z3c/filetype/configure.zcml
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/configure.zcml	2006-08-11 14:54:22 UTC (rev 69404)
+++ z3c.filetype/trunk/src/z3c/filetype/configure.zcml	2006-08-11 15:38:34 UTC (rev 69405)
@@ -0,0 +1,10 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="zope"
+ >
+
+ <subscriber for=".interfaces.ITypeableFile
+                  zope.lifecycleevent.interfaces.IObjectModifiedEvent"
+             handler=".event.handleModified"/>
+ 
+</configure>


Property changes on: z3c.filetype/trunk/src/z3c/filetype/configure.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: z3c.filetype/trunk/src/z3c/filetype/event.py
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/event.py	2006-08-11 14:54:22 UTC (rev 69404)
+++ z3c.filetype/trunk/src/z3c/filetype/event.py	2006-08-11 15:38:34 UTC (rev 69405)
@@ -1,8 +1,19 @@
 from zope.lifecycleevent import ObjectModifiedEvent
-from zope import interface
+from zope.lifecycleevent.interfaces import IObjectModifiedEvent
+from zope import interface, component
 import interfaces
+import api
 
 class FileTypeModifiedEvent(ObjectModifiedEvent):
     interface.implements(interfaces.IFileTypeModifiedEvent)
 
 
+ at component.adapter(interfaces.ITypeableFile,IObjectModifiedEvent)
+def handleModified(typeableFile, event):
+    """handles modification of data"""
+    #import pdb;pdb.set_trace()
+    if interfaces.IFileTypeModifiedEvent.providedBy(event):
+        # do nothing if this is already a filetype modification event
+        return
+    api.applyInterfaces(typeableFile)
+    

Added: z3c.filetype/trunk/src/z3c/filetype/z3c.filetype-configure.zcml
===================================================================
--- z3c.filetype/trunk/src/z3c/filetype/z3c.filetype-configure.zcml	2006-08-11 14:54:22 UTC (rev 69404)
+++ z3c.filetype/trunk/src/z3c/filetype/z3c.filetype-configure.zcml	2006-08-11 15:38:34 UTC (rev 69405)
@@ -0,0 +1 @@
+<include package="z3c.filetype"/>
\ No newline at end of file


Property changes on: z3c.filetype/trunk/src/z3c/filetype/z3c.filetype-configure.zcml
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Checkins mailing list