[Zope3-checkins] CVS: Zope3/src/zope/app/observable - observable.py:1.1.2.1

Nathan Yergler nathan at yergler.net
Tue Mar 23 15:48:13 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/observable
In directory cvs.zope.org:/tmp/cvs-serv4405/src/zope/app/observable

Added Files:
      Tag: observable-branch
	observable.py 
Log Message:


Implemented ObservableAdapter and ObservableAdapterRegistry.




=== Added File Zope3/src/zope/app/observable/observable.py ===
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Observable adapter

$Id: observable.py,v 1.1.2.1 2004/03/23 20:48:12 nathan Exp $
"""

from zope.interface import implements, providedBy
from zope.app.observable.interfaces import IObservable
from zope.app.annotation.interfaces import IAnnotations
from zope.app.adapter.adapter import LocalAdapterRegistry

key = 'zope.app.observable'

class DummyBase:

    adapters = {}
    
    def subscribe(self, arg):
        pass

class ObjectAdapterRegistry(LocalAdapterRegistry):

    dummybase = DummyBase()
    
    def baseFor(self, spec):
        return self.dummybase
    
class ObservableAdapter:

    implements(IObservable)
    
    def __init__(self, context):
        self.context = context

    def subscribe(self, required, provided, subscriber):
        annotations = IAnnotations(self.context)
        registry = annotations.get(key)
        
        if registry is None:
            annotations[key] = registry = ObjectAdapterRegistry(DummyBase())

        registry.subscribe(required, provided, subscriber)

    def notify(self, event, provided):
        import pdb; pdb.set_trace_doctest()
        annotations = IAnnotations(self.context)
        registry = annotations.get(key)
        
        if registry is not None:
            for subscriber in registry.subscriptions([providedBy(event)],
                                                     provided):
                subscriber.notify(event)

        





More information about the Zope3-Checkins mailing list