Back to index

plone3  3.1.7
events.py
Go to the documentation of this file.
00001 
00002 import zope.component
00003 from zope.component.interfaces import (
00004     IUtilityRegistration,
00005     IRegistrationEvent,
00006     )
00007 from interfaces import (
00008     IKSSDemoResource,
00009     IKSSSeleniumTestResource,
00010     IKSSDemoRegistrationEvent,
00011     IKSSDemoRegistryEvent,
00012     IKSSDemoRegistry
00013     )
00014 from zope.interface import implements
00015 
00016 class KSSDemoRegistrationEvent(object):
00017     """Redispatch of registration for demo resource utilities"""
00018     implements(IKSSDemoRegistrationEvent)
00019 
00020 class KSSDemoRegistryEvent(object):
00021     """Redispatch of registration for demo registry utilities"""
00022     implements(IKSSDemoRegistryEvent)
00023 
00024 @zope.component.adapter(IUtilityRegistration, IRegistrationEvent)
00025 def dispatchRegistration(registration, event):
00026     """When a demo utility is registered, add it to the registry.
00027     When a demo utility is registered,  
00028     event handler registered for the particular component registered,
00029     the registration and the event.
00030     """
00031     component = registration.component
00032     # Only dispatch registration of the interesting utilities.
00033     if IKSSDemoResource.providedBy(component) or \
00034             IKSSSeleniumTestResource.providedBy(component):
00035         new_event = KSSDemoRegistrationEvent()
00036         handlers = zope.component.subscribers((component, registration, event, new_event), None)
00037         for handler in handlers:
00038             pass # getting them does the work
00039     if IKSSDemoRegistry.providedBy(component):
00040         new_event = KSSDemoRegistryEvent()
00041         handlers = zope.component.subscribers((component, registration, event, new_event), None)
00042         for handler in handlers:
00043             pass # getting them does the work