[Zope3-Users] problem adding localsitemanager in a subscriber with 3.5dev KGS

Jens W. Klein jens at bluedynamics.com
Fri Feb 27 14:41:22 EST 2009


Hi,

I use the the KGS of zope 3.5dev (I need Python 2.6 because of third 
party code i integrate) and try to build a simple site and add a local 
component registry using a subscriber. It looks like I missed something - 
or I hit a bug in zope3.5dev. But before I report a bug I want to be sure 
that it isnt my fault.

--- interfaces.py ------------------------------------------
class IMySite(IPossibleSite, IContainer):
    """My Site"""

--- site.py ------------------------------------------------
from zope.interface import implements
from zope.component import adapter
from zope.location.interfaces import ISite
from zope.site import LocalSiteManager
from zope.site.site import SiteManagerContainer
from zope.container.btree import BTreeContainer
from zope.container.interfaces import IObjectAddedEvent
from interfaces import IMySite
        
@adapter(IMailmanSite, IObjectAddedEvent)
def setSiteManagerWhenAdded(site, event):
    if not ISite.providedBy(site):
        site.setSiteManager(LocalSiteManager(site))

class MySite(SiteManagerContainer, BTreeContainer):
    implements(IMySite)

--- configure.zcml ------------------------------------------
<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:i18n="http://namespaces.zope.org/i18n"
    i18n_domain="test"
>
  <class class=".site.MySite">
    <implements
        interface="zope.annotation.interfaces.IAttributeAnnotatable"
        />
    <allow attributes="getSiteManager" />
    <require
        permission="zope.ManageServices"
        attributes="setSiteManager"
        />
    <require
        permission="zope.View"
        interface="zope.app.container.interfaces.IReadContainer"
        />
    <require
        permission="zope.ManageContent"
        interface="zope.app.container.intrfaces.IWriteContainer"
        />
 </class>

 <subscriber handler=".site.setSiteManagerWhenAdded" />      
  
</configure>
-------------------------------------------------------------
Then I test this and run into a 

>>> from site import MySite
>>> mysite = MySite()
>>> from zope.app.folder import rootFolder
>>> root = rootFolder()
>>> root[u'mysite'] = mysite

Failed example:
    root[u'mysite'] = mysite
Exception raised:
    Traceback (most recent call last):
      File "/home/jensens/DEV/eggs/zope.testing-3.7.1-py2.6.egg/zope/
testing/doctest.py", line 1356, in __run
        compileflags, 1) in test.globs
      File "<doctest site.txt[7]>", line 1, in <module>
        root[u'mysite'] = mysite
      File "/home/jensens/DEV/eggs/zope.container-3.7.0-py2.6-linux-
i686.egg/zope/container/folder.py", line 98, in __setitem__
        setitem(self, self.data.__setitem__, name, object)
      File "/home/jensens/DEV/eggs/zope.container-3.7.0-py2.6-linux-
i686.egg/zope/container/contained.py", line 590, in setitem
        notify(event)
      File "/home/jensens/DEV/eggs/zope.event-3.4.0-py2.6.egg/zope/event/
__init__.py", line 23, in notify
        subscriber(event)
      File "/home/jensens/DEV/eggs/zope.component-3.5.1-py2.6.egg/zope/
component/event.py", line 26, in dispatch
        for ignored in zope.component.subscribers(event, None):
      File "/home/jensens/DEV/eggs/zope.component-3.5.1-py2.6.egg/zope/
component/_api.py", line 131, in subscribers
        return sitemanager.subscribers(objects, interface)
      File "/home/jensens/DEV/eggs/zope.component-3.5.1-py2.6.egg/zope/
component/registry.py", line 300, in subscribers
        return self.adapters.subscribers(objects, provided)
      File "/home/jensens/DEV/eggs/zope.interface-3.5.0-py2.6-linux-
i686.egg/zope/interface/adapter.py", line 535, in subscribers
        subscription(*objects)
      File "/home/jensens/DEV/eggs/zope.component-3.5.1-py2.6.egg/zope/
component/event.py", line 33, in objectEventNotify
        adapters = zope.component.subscribers((event.object, event), None)
      File "/home/jensens/DEV/eggs/zope.component-3.5.1-py2.6.egg/zope/
component/_api.py", line 131, in subscribers
        return sitemanager.subscribers(objects, interface)
      File "/home/jensens/DEV/eggs/zope.component-3.5.1-py2.6.egg/zope/
component/registry.py", line 300, in subscribers
        return self.adapters.subscribers(objects, provided)
      File "/home/jensens/DEV/eggs/zope.interface-3.5.0-py2.6-linux-
i686.egg/zope/interface/adapter.py", line 535, in subscribers
        subscription(*objects)
      File "/home/jensens/DEV/eggs/zope.site-3.6.0-py2.6.egg/zope/site/
site.py", line 256, in changeSiteConfigurationAfterMove
        site.getSiteManager().__bases__ = (next, )
      File "/home/jensens/DEV/eggs/zope.component-3.5.1-py2.6.egg/zope/
component/registry.py", line 65, in <lambda>
        lambda self, bases: self._setBases(bases),
      File "/home/jensens/DEV/eggs/zope.site-3.6.0-py2.6.egg/zope/site/
site.py", line 161, in _setBases
        super(LocalSiteManager, self)._setBases(bases)
      File "/home/jensens/DEV/eggs/zope.component-3.5.1-py2.6.egg/zope/
component/registry.py", line 58, in _setBases
        base.adapters for base in bases])
    AttributeError: 'NoneType' object has no attribute 'adapters'    

It calls the subscriber, adds the LocalSiteManager and then another event 
happens and the subscriber zope.site.site.changeSiteConfigurationAfterMove
is called (line 251). Here is the code in there:

    if event.newParent is not None:
        next = _findNextSiteManager(site)
        site.getSiteManager().__bases__ 

next is None here, so __bases__ has a None in the list.

Btw., the way the sitemanager is added is the same as described in 
Phillip von Weiterhausens book.

Whats wrong?

thanks for hints!
-- 
Jens W. Klein, BlueDynamics Alliance, http://bluedynamics.com



More information about the Zope3-users mailing list