File: events.py

package info (click to toggle)
plone3 3.1.3-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 73,972 kB
  • ctags: 39,149
  • sloc: python: 209,481; xml: 25,065; sh: 1,395; makefile: 585; php: 129; lisp: 54
file content (43 lines) | stat: -rw-r--r-- 1,644 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

import zope.component
from zope.component.interfaces import (
    IUtilityRegistration,
    IRegistrationEvent,
    )
from interfaces import (
    IKSSDemoResource,
    IKSSSeleniumTestResource,
    IKSSDemoRegistrationEvent,
    IKSSDemoRegistryEvent,
    IKSSDemoRegistry
    )
from zope.interface import implements

class KSSDemoRegistrationEvent(object):
    """Redispatch of registration for demo resource utilities"""
    implements(IKSSDemoRegistrationEvent)

class KSSDemoRegistryEvent(object):
    """Redispatch of registration for demo registry utilities"""
    implements(IKSSDemoRegistryEvent)

@zope.component.adapter(IUtilityRegistration, IRegistrationEvent)
def dispatchRegistration(registration, event):
    """When a demo utility is registered, add it to the registry.
    When a demo utility is registered,  
    event handler registered for the particular component registered,
    the registration and the event.
    """
    component = registration.component
    # Only dispatch registration of the interesting utilities.
    if IKSSDemoResource.providedBy(component) or \
            IKSSSeleniumTestResource.providedBy(component):
        new_event = KSSDemoRegistrationEvent()
        handlers = zope.component.subscribers((component, registration, event, new_event), None)
        for handler in handlers:
            pass # getting them does the work
    if IKSSDemoRegistry.providedBy(component):
        new_event = KSSDemoRegistryEvent()
        handlers = zope.component.subscribers((component, registration, event, new_event), None)
        for handler in handlers:
            pass # getting them does the work