[Checkins] SVN: zope.site/tags/3.6.1/ Tag 3.6.1
Dan Korostelev
nadako at gmail.com
Sat Feb 28 04:53:43 EST 2009
Log message for revision 97376:
Tag 3.6.1
Changed:
A zope.site/tags/3.6.1/
D zope.site/tags/3.6.1/CHANGES.txt
A zope.site/tags/3.6.1/CHANGES.txt
D zope.site/tags/3.6.1/README.txt
A zope.site/tags/3.6.1/README.txt
D zope.site/tags/3.6.1/setup.py
A zope.site/tags/3.6.1/setup.py
D zope.site/tags/3.6.1/src/zope/site/interfaces.py
A zope.site/tags/3.6.1/src/zope/site/interfaces.py
D zope.site/tags/3.6.1/src/zope/site/site.py
A zope.site/tags/3.6.1/src/zope/site/site.py
-=-
Deleted: zope.site/tags/3.6.1/CHANGES.txt
===================================================================
--- zope.site/trunk/CHANGES.txt 2009-02-28 07:45:58 UTC (rev 97369)
+++ zope.site/tags/3.6.1/CHANGES.txt 2009-02-28 09:53:43 UTC (rev 97376)
@@ -1,26 +0,0 @@
-=======
-CHANGES
-=======
-
-3.6.1 (unreleased)
-------------------
-
-- Import symbols moved from zope.traversing to zope.location from the new
- location.
-
-- Don't fail when changing component registry bases while moving ISite
- object to non-ISite object.
-
-- Allow specify whether to create 'default' SiteManagementFolder on
- initializing LocalSiteManager. Use the ``default_folder`` argument.
-
-3.6.0 (2009-1-31)
------------------
-
-- Use zope.container instead of zope.app.container.
-
-3.5.1 (2009-01-27)
-------------------
-
-- Extracted from zope.app.component (trunk, 3.5.1 under development)
- as part of an effort to clean up dependencies between Zope packages.
Copied: zope.site/tags/3.6.1/CHANGES.txt (from rev 97374, zope.site/trunk/CHANGES.txt)
===================================================================
--- zope.site/tags/3.6.1/CHANGES.txt (rev 0)
+++ zope.site/tags/3.6.1/CHANGES.txt 2009-02-28 09:53:43 UTC (rev 97376)
@@ -0,0 +1,35 @@
+=======
+CHANGES
+=======
+
+3.6.1 (2009-02-28)
+------------------
+
+- Import symbols moved from zope.traversing to zope.location from the new
+ location.
+
+- Don't fail when changing component registry bases while moving ISite
+ object to non-ISite object.
+
+- Allow specify whether to create 'default' SiteManagementFolder on
+ initializing LocalSiteManager. Use the ``default_folder`` argument.
+
+- Add a containment constraint to the SiteManagementFolder that makes
+ it only available to be contained in ILocalSiteManagers and other
+ ISiteManagementFolders.
+
+- Change package's mailing list address to zope-dev at zope.org, as
+ zope3-dev at zope.org is now retired.
+
+- Remove old unused code. Update package description.
+
+3.6.0 (2009-01-31)
+------------------
+
+- Use zope.container instead of zope.app.container.
+
+3.5.1 (2009-01-27)
+------------------
+
+- Extracted from zope.app.component (trunk, 3.5.1 under development)
+ as part of an effort to clean up dependencies between Zope packages.
Deleted: zope.site/tags/3.6.1/README.txt
===================================================================
--- zope.site/trunk/README.txt 2009-02-28 07:45:58 UTC (rev 97369)
+++ zope.site/tags/3.6.1/README.txt 2009-02-28 09:53:43 UTC (rev 97376)
@@ -1,2 +0,0 @@
-This package allows for local component registries and local component
-management.
Copied: zope.site/tags/3.6.1/README.txt (from rev 97370, zope.site/trunk/README.txt)
===================================================================
--- zope.site/tags/3.6.1/README.txt (rev 0)
+++ zope.site/tags/3.6.1/README.txt 2009-02-28 09:53:43 UTC (rev 97376)
@@ -0,0 +1,2 @@
+This package adds support for persistent local component registries for
+the zope component architecture.
Deleted: zope.site/tags/3.6.1/setup.py
===================================================================
--- zope.site/trunk/setup.py 2009-02-28 07:45:58 UTC (rev 97369)
+++ zope.site/tags/3.6.1/setup.py 2009-02-28 09:53:43 UTC (rev 97376)
@@ -1,75 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-#
-##############################################################################
-"""Setup for zope.app.catalog package
-
-$Id: setup.py 80209 2007-09-27 09:38:31Z berndroessl $
-"""
-import os
-from setuptools import setup, find_packages
-
-def read(*rnames):
- return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
-
-setup(name='zope.site',
- version = '3.6.1dev',
- author='Zope Corporation and Contributors',
- author_email='zope3-dev at zope.org',
- description='Local Zope Component Support',
- long_description=(
- read('README.txt')
- + '\n\n' +
- 'Detailed Documentation\n'
- '**********************\n'
- + '\n\n' +
- read('src', 'zope', 'site', 'README.txt')
- + '\n\n' +
- read('src', 'zope', 'site', 'site.txt')
- + '\n\n' +
- read('CHANGES.txt')
- ),
- keywords = "zope component architecture local",
- classifiers = [
- 'Development Status :: 5 - Production/Stable',
- 'Environment :: Web Environment',
- 'Intended Audience :: Developers',
- 'License :: OSI Approved :: Zope Public License',
- 'Programming Language :: Python',
- 'Natural Language :: English',
- 'Operating System :: OS Independent',
- 'Topic :: Internet :: WWW/HTTP',
- 'Framework :: Zope3'],
- url='http://pypi.python.org/pypi/zope.site',
- license='ZPL 2.1',
- packages=find_packages('src'),
- package_dir = {'': 'src'},
- namespace_packages=['zope'],
- extras_require=dict(
- test=['zope.app.testing',]),
- install_requires=[
- 'setuptools',
- 'zope.annotation',
- 'zope.container',
- 'zope.security',
- 'zope.component [hook]',
- 'zope.configuration',
- 'zope.event',
- 'zope.interface',
- 'zope.lifecycleevent',
- 'zope.location>3.4.0b1',
- 'zope.traversing',
- ],
- include_package_data = True,
- zip_safe = False,
- )
-
Copied: zope.site/tags/3.6.1/setup.py (from rev 97375, zope.site/trunk/setup.py)
===================================================================
--- zope.site/tags/3.6.1/setup.py (rev 0)
+++ zope.site/tags/3.6.1/setup.py 2009-02-28 09:53:43 UTC (rev 97376)
@@ -0,0 +1,75 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Setup for zope.site package
+
+$Id: setup.py 80209 2007-09-27 09:38:31Z berndroessl $
+"""
+import os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+ return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+setup(name='zope.site',
+ version = '3.6.1',
+ author='Zope Corporation and Contributors',
+ author_email='zope-dev at zope.org',
+ description='Local registries for zope component architecture',
+ long_description=(
+ read('README.txt')
+ + '\n\n' +
+ 'Detailed Documentation\n'
+ '**********************\n'
+ + '\n\n' +
+ read('src', 'zope', 'site', 'README.txt')
+ + '\n\n' +
+ read('src', 'zope', 'site', 'site.txt')
+ + '\n\n' +
+ read('CHANGES.txt')
+ ),
+ keywords = "zope component architecture local",
+ classifiers = [
+ 'Development Status :: 5 - Production/Stable',
+ 'Environment :: Web Environment',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: Zope Public License',
+ 'Programming Language :: Python',
+ 'Natural Language :: English',
+ 'Operating System :: OS Independent',
+ 'Topic :: Internet :: WWW/HTTP',
+ 'Framework :: Zope3'],
+ url='http://pypi.python.org/pypi/zope.site',
+ license='ZPL 2.1',
+ packages=find_packages('src'),
+ package_dir = {'': 'src'},
+ namespace_packages=['zope'],
+ extras_require=dict(
+ test=['zope.app.testing',]),
+ install_requires=[
+ 'setuptools',
+ 'zope.annotation',
+ 'zope.container',
+ 'zope.security',
+ 'zope.component [hook]',
+ 'zope.configuration',
+ 'zope.event',
+ 'zope.interface',
+ 'zope.lifecycleevent',
+ 'zope.location>3.4.0b1',
+ 'zope.traversing',
+ ],
+ include_package_data = True,
+ zip_safe = False,
+ )
+
Deleted: zope.site/tags/3.6.1/src/zope/site/interfaces.py
===================================================================
--- zope.site/trunk/src/zope/site/interfaces.py 2009-02-28 07:45:58 UTC (rev 97369)
+++ zope.site/tags/3.6.1/src/zope/site/interfaces.py 2009-02-28 09:53:43 UTC (rev 97376)
@@ -1,88 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-#
-##############################################################################
-"""Interfaces for the Local Component Architecture
-
-$Id$
-"""
-
-import zope.interface
-import zope.component.interfaces
-import zope.container.interfaces
-import zope.location.interfaces
-
-from zope.location.interfaces import IPossibleSite
-from zope.annotation.interfaces import IAttributeAnnotatable
-
-
-class INewLocalSite(zope.interface.Interface):
- """Event: a local site was created
- """
-
- manager = zope.interface.Attribute("The new site manager")
-
-class NewLocalSite(object):
- """Event: a local site was created
- """
- zope.interface.implements(INewLocalSite)
-
- def __init__(self, manager):
- self.manager = manager
-
-
-class ILocalSiteManager(zope.component.interfaces.IComponents):
- """Site Managers act as containers for registerable components.
-
- If a Site Manager is asked for an adapter or utility, it checks for those
- it contains before using a context-based lookup to find another site
- manager to delegate to. If no other site manager is found they defer to
- the global site manager which contains file based utilities and adapters.
- """
-
- subs = zope.interface.Attribute(
- "A collection of registries that describe the next level "
- "of the registry tree. They are the children of this "
- "registry node. This attribute should never be "
- "manipulated manually. Use `addSub()` and `removeSub()` "
- "instead.")
-
- def addSub(sub):
- """Add a new sub-registry to the node.
-
- Important: This method should *not* be used manually. It is
- automatically called by `setNext()`. To add a new registry to the
- tree, use `sub.setNext(self, self.base)` instead!
- """
-
- def removeSub(sub):
- """Remove a sub-registry to the node.
-
- Important: This method should *not* be used manually. It is
- automatically called by `setNext()`. To remove a registry from the
- tree, use `sub.setNext(None)` instead!
- """
-
-
-class ISiteManagementFolder(zope.container.interfaces.IContainer):
- """Component and component registration containers."""
-
- # XXX we need to figure out how to constrain this or, alternatively,
- # just use regular folders, which is probably the beter choice.
- # zope.container.constraints.containers(ILocalSiteManager)
-
-class IFolder(zope.container.interfaces.IContainer, IPossibleSite,
- IAttributeAnnotatable):
- """The standard Zope Folder object interface."""
-
-class IRootFolder(IFolder, zope.location.interfaces.IRoot):
- """The standard Zope root Folder object interface."""
Copied: zope.site/tags/3.6.1/src/zope/site/interfaces.py (from rev 97373, zope.site/trunk/src/zope/site/interfaces.py)
===================================================================
--- zope.site/tags/3.6.1/src/zope/site/interfaces.py (rev 0)
+++ zope.site/tags/3.6.1/src/zope/site/interfaces.py 2009-02-28 09:53:43 UTC (rev 97376)
@@ -0,0 +1,88 @@
+##############################################################################
+#
+# Copyright (c) 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Interfaces for the Local Component Architecture
+
+$Id$
+"""
+
+import zope.interface
+import zope.component.interfaces
+import zope.container.interfaces
+import zope.container.constraints
+import zope.location.interfaces
+
+from zope.location.interfaces import IPossibleSite
+from zope.annotation.interfaces import IAttributeAnnotatable
+
+
+class INewLocalSite(zope.interface.Interface):
+ """Event: a local site was created
+ """
+
+ manager = zope.interface.Attribute("The new site manager")
+
+class NewLocalSite(object):
+ """Event: a local site was created
+ """
+ zope.interface.implements(INewLocalSite)
+
+ def __init__(self, manager):
+ self.manager = manager
+
+
+class ILocalSiteManager(zope.component.interfaces.IComponents):
+ """Site Managers act as containers for registerable components.
+
+ If a Site Manager is asked for an adapter or utility, it checks for those
+ it contains before using a context-based lookup to find another site
+ manager to delegate to. If no other site manager is found they defer to
+ the global site manager which contains file based utilities and adapters.
+ """
+
+ subs = zope.interface.Attribute(
+ "A collection of registries that describe the next level "
+ "of the registry tree. They are the children of this "
+ "registry node. This attribute should never be "
+ "manipulated manually. Use `addSub()` and `removeSub()` "
+ "instead.")
+
+ def addSub(sub):
+ """Add a new sub-registry to the node.
+
+ Important: This method should *not* be used manually. It is
+ automatically called by `setNext()`. To add a new registry to the
+ tree, use `sub.setNext(self, self.base)` instead!
+ """
+
+ def removeSub(sub):
+ """Remove a sub-registry to the node.
+
+ Important: This method should *not* be used manually. It is
+ automatically called by `setNext()`. To remove a registry from the
+ tree, use `sub.setNext(None)` instead!
+ """
+
+
+class ISiteManagementFolder(zope.container.interfaces.IContainer):
+ """Component and component registration containers."""
+
+ zope.container.constraints.containers(
+ ILocalSiteManager, '.ISiteManagementFolder')
+
+class IFolder(zope.container.interfaces.IContainer, IPossibleSite,
+ IAttributeAnnotatable):
+ """The standard Zope Folder object interface."""
+
+class IRootFolder(IFolder, zope.location.interfaces.IRoot):
+ """The standard Zope root Folder object interface."""
Deleted: zope.site/tags/3.6.1/src/zope/site/site.py
===================================================================
--- zope.site/trunk/src/zope/site/site.py 2009-02-28 07:45:58 UTC (rev 97369)
+++ zope.site/tags/3.6.1/src/zope/site/site.py 2009-02-28 09:53:43 UTC (rev 97376)
@@ -1,259 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-#
-##############################################################################
-"""Site and Local Site Manager implementation
-
-A local site manager has a number of roles:
-
- - A local site manager, that provides a local adapter and utility registry.
-
- - A place to do TTW development and/or to manage database-based code.
-
- - A registry for persistent modules. The Zope 3 import hook uses the
- SiteManager to search for modules.
-
-$Id$
-"""
-
-import zope.event
-import zope.interface
-import zope.component
-import zope.component.persistentregistry
-import zope.component.interfaces
-import zope.traversing.api
-import zope.location
-import zope.location.interfaces
-
-from zope.component.interfaces import ComponentLookupError
-from zope.lifecycleevent import ObjectCreatedEvent
-from zope.filerepresentation.interfaces import IDirectoryFactory
-
-from zope.container.btree import BTreeContainer
-from zope.container.contained import Contained
-
-from zope.site import interfaces
-from zope.site.hooks import setSite
-
-##############################################################################
-# from zope.app.module import resolve
-
-# Break the dependency on zope.app.module. In the long run,
-# we need to handle this better. Perhaps througha utility.
-
-## def findModule(name, context=None):
-## """Find the module matching the provided name."""
-## module = ZopeModuleRegistry.findModule(name)
-## return module or sys.modules.get(name)
-
-import sys
-
-def resolve(name, context=None):
- """Resolve a dotted name to a Python object."""
- pos = name.rfind('.')
- mod = sys.modules.get(name[:pos])
-## mod = findModule(name[:pos], context)
- return getattr(mod, name[pos+1:], None)
-
-# from zope.app.module import resolve
-##############################################################################
-
-class SiteManagementFolder(BTreeContainer):
- zope.interface.implements(interfaces.ISiteManagementFolder)
-
-
-class SMFolderFactory(object):
- zope.interface.implements(IDirectoryFactory)
-
- def __init__(self, context):
- self.context = context
-
- def __call__(self, name):
- return SiteManagementFolder()
-
-
-class SiteManagerContainer(Contained):
- """Implement access to the site manager (++etc++site).
-
- This is a mix-in that implements the IPossibleSite
- interface; for example, it is used by the Folder implementation.
- """
- zope.interface.implements(zope.location.interfaces.IPossibleSite)
-
- _sm = None
-
- def getSiteManager(self):
- if self._sm is not None:
- return self._sm
- else:
- raise ComponentLookupError('no site manager defined')
-
- def setSiteManager(self, sm):
- if zope.location.interfaces.ISite.providedBy(self):
- raise TypeError("Already a site")
-
- if zope.component.interfaces.IComponentLookup.providedBy(sm):
- self._sm = sm
- sm.__name__ = '++etc++site'
- sm.__parent__ = self
- else:
- raise ValueError('setSiteManager requires an IComponentLookup')
-
- zope.interface.directlyProvides(
- self, zope.location.interfaces.ISite,
- zope.interface.directlyProvidedBy(self))
- zope.event.notify(interfaces.NewLocalSite(sm))
-
-def _findNextSiteManager(site):
- while True:
- if zope.location.interfaces.IRoot.providedBy(site):
- # we're the root site, return None
- return None
-
- try:
- site = zope.traversing.api.getParent(site)
- except TypeError:
- # there was not enough context; probably run from a test
- return None
-
- if zope.location.interfaces.ISite.providedBy(site):
- return site.getSiteManager()
-
-
-class _LocalAdapterRegistry(
- zope.component.persistentregistry.PersistentAdapterRegistry,
- zope.location.Location,
- ):
- pass
-
-class LocalSiteManager(
- BTreeContainer,
- zope.component.persistentregistry.PersistentComponents,
- ):
- """Local Site Manager implementation"""
- zope.interface.implements(interfaces.ILocalSiteManager)
-
- subs = ()
-
- def _setBases(self, bases):
-
- # Update base subs
- for base in self.__bases__:
- if ((base not in bases)
- and interfaces.ILocalSiteManager.providedBy(base)
- ):
- base.removeSub(self)
-
- for base in bases:
- if ((base not in self.__bases__)
- and interfaces.ILocalSiteManager.providedBy(base)
- ):
- base.addSub(self)
-
- super(LocalSiteManager, self)._setBases(bases)
-
- def __init__(self, site, default_folder=True):
- # Locate the site manager
- self.__parent__ = site
- self.__name__ = '++etc++site'
-
- BTreeContainer.__init__(self)
- zope.component.persistentregistry.PersistentComponents.__init__(self)
-
- next = _findNextSiteManager(site)
- if next is None:
- next = zope.component.getGlobalSiteManager()
- self.__bases__ = (next, )
-
- # Setup default site management folder if requested
- if default_folder:
- folder = SiteManagementFolder()
- zope.event.notify(ObjectCreatedEvent(folder))
- self['default'] = folder
-
- def _init_registries(self):
- self.adapters = _LocalAdapterRegistry()
- self.utilities = _LocalAdapterRegistry()
- self.adapters.__parent__ = self.utilities.__parent__ = self
- self.adapters.__name__ = u'adapters'
- self.utilities.__name__ = u'utilities'
-
- def addSub(self, sub):
- """See interfaces.registration.ILocatedRegistry"""
- self.subs += (sub, )
-
- def removeSub(self, sub):
- """See interfaces.registration.ILocatedRegistry"""
- self.subs = tuple(
- [s for s in self.subs if s is not sub] )
-
- def __getRegistry(self, registration):
- """Determine the correct registry for the registration."""
- if interfaces.IUtilityRegistration.providedBy(registration):
- return self.utilities
- elif interfaces.IAdapterRegistration.providedBy(registration):
- return self.adapters
- raise ValueError("Unable to detect registration type or registration "
- "type is not supported. The registration object must "
- "provide `IAdapterRegistration` or "
- "`IUtilityRegistration`.")
-
-def threadSiteSubscriber(ob, event):
- """A subscriber to BeforeTraverseEvent
-
- Sets the 'site' thread global if the object traversed is a site.
- """
- setSite(ob)
-
-
-def clearThreadSiteSubscriber(event):
- """A subscriber to EndRequestEvent
-
- Cleans up the site thread global after the request is processed.
- """
- clearSite()
-
-# Clear the site thread global
-clearSite = setSite
-try:
- from zope.testing.cleanup import addCleanUp
-except ImportError:
- pass
-else:
- addCleanUp(clearSite)
-
-
- at zope.component.adapter(zope.interface.Interface)
- at zope.interface.implementer(zope.component.interfaces.IComponentLookup)
-def SiteManagerAdapter(ob):
- """An adapter from ILocation to IComponentLookup.
-
- The ILocation is interpreted flexibly, we just check for
- ``__parent__``.
- """
- current = ob
- while True:
- if zope.location.interfaces.ISite.providedBy(current):
- return current.getSiteManager()
- current = getattr(current, '__parent__', None)
- if current is None:
- # It is not a location or has no parent, so we return the global
- # site manager
- return zope.component.getGlobalSiteManager()
-
-def changeSiteConfigurationAfterMove(site, event):
- """After a site is moved, its site manager links have to be updated."""
- if event.newParent is not None:
- next = _findNextSiteManager(site)
- if next is None:
- next = zope.component.getGlobalSiteManager()
- site.getSiteManager().__bases__ = (next, )
Copied: zope.site/tags/3.6.1/src/zope/site/site.py (from rev 97374, zope.site/trunk/src/zope/site/site.py)
===================================================================
--- zope.site/tags/3.6.1/src/zope/site/site.py (rev 0)
+++ zope.site/tags/3.6.1/src/zope/site/site.py 2009-02-28 09:53:43 UTC (rev 97376)
@@ -0,0 +1,227 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Site and Local Site Manager implementation
+
+A local site manager has a number of roles:
+
+ - A local site manager, that provides a local adapter and utility registry.
+
+ - A place to do TTW development and/or to manage database-based code.
+
+ - A registry for persistent modules. The Zope 3 import hook uses the
+ SiteManager to search for modules.
+
+$Id$
+"""
+
+import zope.event
+import zope.interface
+import zope.component
+import zope.component.persistentregistry
+import zope.component.interfaces
+import zope.traversing.api
+import zope.location
+import zope.location.interfaces
+
+from zope.component.interfaces import ComponentLookupError
+from zope.lifecycleevent import ObjectCreatedEvent
+from zope.filerepresentation.interfaces import IDirectoryFactory
+
+from zope.container.btree import BTreeContainer
+from zope.container.contained import Contained
+
+from zope.site import interfaces
+from zope.site.hooks import setSite
+
+
+class SiteManagementFolder(BTreeContainer):
+ zope.interface.implements(interfaces.ISiteManagementFolder)
+
+
+class SMFolderFactory(object):
+ zope.interface.implements(IDirectoryFactory)
+
+ def __init__(self, context):
+ self.context = context
+
+ def __call__(self, name):
+ return SiteManagementFolder()
+
+
+class SiteManagerContainer(Contained):
+ """Implement access to the site manager (++etc++site).
+
+ This is a mix-in that implements the IPossibleSite
+ interface; for example, it is used by the Folder implementation.
+ """
+ zope.interface.implements(zope.location.interfaces.IPossibleSite)
+
+ _sm = None
+
+ def getSiteManager(self):
+ if self._sm is not None:
+ return self._sm
+ else:
+ raise ComponentLookupError('no site manager defined')
+
+ def setSiteManager(self, sm):
+ if zope.location.interfaces.ISite.providedBy(self):
+ raise TypeError("Already a site")
+
+ if zope.component.interfaces.IComponentLookup.providedBy(sm):
+ self._sm = sm
+ sm.__name__ = '++etc++site'
+ sm.__parent__ = self
+ else:
+ raise ValueError('setSiteManager requires an IComponentLookup')
+
+ zope.interface.directlyProvides(
+ self, zope.location.interfaces.ISite,
+ zope.interface.directlyProvidedBy(self))
+ zope.event.notify(interfaces.NewLocalSite(sm))
+
+def _findNextSiteManager(site):
+ while True:
+ if zope.location.interfaces.IRoot.providedBy(site):
+ # we're the root site, return None
+ return None
+
+ try:
+ site = zope.traversing.api.getParent(site)
+ except TypeError:
+ # there was not enough context; probably run from a test
+ return None
+
+ if zope.location.interfaces.ISite.providedBy(site):
+ return site.getSiteManager()
+
+
+class _LocalAdapterRegistry(
+ zope.component.persistentregistry.PersistentAdapterRegistry,
+ zope.location.Location,
+ ):
+ pass
+
+class LocalSiteManager(
+ BTreeContainer,
+ zope.component.persistentregistry.PersistentComponents,
+ ):
+ """Local Site Manager implementation"""
+ zope.interface.implements(interfaces.ILocalSiteManager)
+
+ subs = ()
+
+ def _setBases(self, bases):
+
+ # Update base subs
+ for base in self.__bases__:
+ if ((base not in bases)
+ and interfaces.ILocalSiteManager.providedBy(base)
+ ):
+ base.removeSub(self)
+
+ for base in bases:
+ if ((base not in self.__bases__)
+ and interfaces.ILocalSiteManager.providedBy(base)
+ ):
+ base.addSub(self)
+
+ super(LocalSiteManager, self)._setBases(bases)
+
+ def __init__(self, site, default_folder=True):
+ # Locate the site manager
+ self.__parent__ = site
+ self.__name__ = '++etc++site'
+
+ BTreeContainer.__init__(self)
+ zope.component.persistentregistry.PersistentComponents.__init__(self)
+
+ next = _findNextSiteManager(site)
+ if next is None:
+ next = zope.component.getGlobalSiteManager()
+ self.__bases__ = (next, )
+
+ # Setup default site management folder if requested
+ if default_folder:
+ folder = SiteManagementFolder()
+ zope.event.notify(ObjectCreatedEvent(folder))
+ self['default'] = folder
+
+ def _init_registries(self):
+ self.adapters = _LocalAdapterRegistry()
+ self.utilities = _LocalAdapterRegistry()
+ self.adapters.__parent__ = self.utilities.__parent__ = self
+ self.adapters.__name__ = u'adapters'
+ self.utilities.__name__ = u'utilities'
+
+ def addSub(self, sub):
+ """See interfaces.registration.ILocatedRegistry"""
+ self.subs += (sub, )
+
+ def removeSub(self, sub):
+ """See interfaces.registration.ILocatedRegistry"""
+ self.subs = tuple(
+ [s for s in self.subs if s is not sub] )
+
+
+def threadSiteSubscriber(ob, event):
+ """A subscriber to BeforeTraverseEvent
+
+ Sets the 'site' thread global if the object traversed is a site.
+ """
+ setSite(ob)
+
+
+def clearThreadSiteSubscriber(event):
+ """A subscriber to EndRequestEvent
+
+ Cleans up the site thread global after the request is processed.
+ """
+ clearSite()
+
+# Clear the site thread global
+clearSite = setSite
+try:
+ from zope.testing.cleanup import addCleanUp
+except ImportError:
+ pass
+else:
+ addCleanUp(clearSite)
+
+
+ at zope.component.adapter(zope.interface.Interface)
+ at zope.interface.implementer(zope.component.interfaces.IComponentLookup)
+def SiteManagerAdapter(ob):
+ """An adapter from ILocation to IComponentLookup.
+
+ The ILocation is interpreted flexibly, we just check for
+ ``__parent__``.
+ """
+ current = ob
+ while True:
+ if zope.location.interfaces.ISite.providedBy(current):
+ return current.getSiteManager()
+ current = getattr(current, '__parent__', None)
+ if current is None:
+ # It is not a location or has no parent, so we return the global
+ # site manager
+ return zope.component.getGlobalSiteManager()
+
+def changeSiteConfigurationAfterMove(site, event):
+ """After a site is moved, its site manager links have to be updated."""
+ if event.newParent is not None:
+ next = _findNextSiteManager(site)
+ if next is None:
+ next = zope.component.getGlobalSiteManager()
+ site.getSiteManager().__bases__ = (next, )
More information about the Checkins
mailing list