[Zope3-checkins]
SVN: Zope3/branches/srichter-blow-services/src/zope/
Completed database evolution script. On the way I also fixed
a lot of the
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sat Feb 12 21:16:56 EST 2005
Log message for revision 29129:
Completed database evolution script. On the way I also fixed a lot of the
BBB code to better support the old APIs.
I am getting there!
Changed:
A Zope3/branches/srichter-blow-services/src/zope/app/adapter/
A Zope3/branches/srichter-blow-services/src/zope/app/adapter/__init__.py
A Zope3/branches/srichter-blow-services/src/zope/app/adapter/adapter.py
U Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/registration.py
U Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/site.py
U Zope3/branches/srichter-blow-services/src/zope/app/component/registration.py
U Zope3/branches/srichter-blow-services/src/zope/app/component/site.py
U Zope3/branches/srichter-blow-services/src/zope/app/pluggableauth/__init__.py
U Zope3/branches/srichter-blow-services/src/zope/app/site/interfaces.py
U Zope3/branches/srichter-blow-services/src/zope/app/site/service.py
U Zope3/branches/srichter-blow-services/src/zope/app/utility/utility.py
U Zope3/branches/srichter-blow-services/src/zope/app/zopeappgenerations/evolve1.py
U Zope3/branches/srichter-blow-services/src/zope/component/bbb/utility.py
-=-
Added: Zope3/branches/srichter-blow-services/src/zope/app/adapter/__init__.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/adapter/__init__.py 2005-02-12 22:40:27 UTC (rev 29128)
+++ Zope3/branches/srichter-blow-services/src/zope/app/adapter/__init__.py 2005-02-13 02:16:56 UTC (rev 29129)
@@ -0,0 +1 @@
+# Make package
Added: Zope3/branches/srichter-blow-services/src/zope/app/adapter/adapter.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/adapter/adapter.py 2005-02-12 22:40:27 UTC (rev 29128)
+++ Zope3/branches/srichter-blow-services/src/zope/app/adapter/adapter.py 2005-02-13 02:16:56 UTC (rev 29129)
@@ -0,0 +1,24 @@
+# Copyright (c) 2003 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.
+##############################################################################
+"""Local adapter service implementation.
+
+$Id$
+"""
+from persistent import Persistent
+from zope.deprecation import deprecated
+
+# Hopefully noone was using this yet.
+class LocalAdapterService(Persistent):
+ pass
+
+deprecated('LocalAdapterService',
+ 'Services have been removed. Use site manager API. '
+ 'The reference will be gone in X3.3.')
Modified: Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/registration.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/registration.py 2005-02-12 22:40:27 UTC (rev 29128)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/registration.py 2005-02-13 02:16:56 UTC (rev 29129)
@@ -16,7 +16,12 @@
$Id$
"""
__docformat__ = "reStructuredText"
+from persistent import Persistent
+from zope.cachedescriptors.property import Lazy
from zope.interface import implements
+from zope.proxy import removeAllProxies
+from zope.security.checker import InterfaceChecker, CheckerPublic
+from zope.security.proxy import Proxy, removeSecurityProxy
from zope.app import zapi
from zope.app.container.contained import Contained
@@ -24,7 +29,7 @@
import interfaces
-class RegistrationStack(Contained):
+class RegistrationStack(Contained, Persistent):
"""Registration registry implemention
A registration stack provides support for a collection of
@@ -107,6 +112,96 @@
return tuple(data)
+NULL_COMPONENT = object()
+
+class BBBComponentRegistration(object):
+
+ _BBB_componentPath = None
+
+ def __init__(self, component, permission=None):
+ # BBB: 12/05/2004
+ if isinstance(component, (str, unicode)):
+ self.componentPath = component
+ else:
+ # We always want to set the plain component. Untrusted code will
+ # get back a proxied component anyways.
+ self.component = removeSecurityProxy(component)
+ if permission == 'zope.Public':
+ permission = CheckerPublic
+ self.permission = permission
+
+ def getComponent(self):
+ return self.__BBB_getComponent()
+
+ def __BBB_getComponent(self):
+ if self._component is NULL_COMPONENT:
+ return self.__BBB_old_getComponent(self._BBB_componentPath)
+
+ # This condition should somehow make it in the final code, since it
+ # honors the permission.
+ if self.permission:
+ checker = InterfaceChecker(self.getInterface(), self.permission)
+ return Proxy(self._component, checker)
+
+ return self._component
+
+ def __BBB_old_getComponent(self, path):
+ service_manager = zapi.getSiteManager(self)
+
+ # Get the root and unproxy it
+ if path.startswith("/"):
+ # Absolute path
+ root = removeAllProxies(zapi.getRoot(service_manager))
+ component = zapi.traverse(root, path)
+ else:
+ # Relative path.
+ ancestor = self.__parent__.__parent__
+ component = zapi.traverse(ancestor, path)
+
+ if self.permission:
+ if type(component) is Proxy:
+ # There should be at most one security Proxy around an object.
+ # So, if we're going to add a new security proxy, we need to
+ # remove any existing one.
+ component = removeSecurityProxy(component)
+
+ interface = self.getInterface()
+
+ checker = InterfaceChecker(interface, self.permission)
+
+ component = Proxy(component, checker)
+
+ return component
+
+ def __BBB_setComponent(self, component):
+ self._BBB_componentPath = None
+ self._component = component
+
+ component = property(__BBB_getComponent, __BBB_setComponent)
+
+ def __BBB_getComponentPath(self):
+ if self._BBB_componentPath is not None:
+ return self._BBB_componentPath
+ return '/' + '/'.join(zapi.getPath(self.component))
+
+ def __BBB_setComponentPath(self, path):
+ self._component = NULL_COMPONENT
+ self._BBB_componentPath = path
+
+ componentPath = property(__BBB_getComponentPath, __BBB_setComponentPath)
+
+ def __setstate__(self, dict):
+ super(BBBComponentRegistration, self).__setstate__(dict)
+ # For some reason the component path is not set correctly by the
+ # default __setstate__ mechanism.
+ if 'componentPath' in dict:
+ self._component = NULL_COMPONENT
+ self._BBB_componentPath = dict['componentPath']
+
+ if isinstance(self._BBB_componentPath, (str, unicode)):
+ self._component = NULL_COMPONENT
+
+
class BBBRegistry(object):
def queryRegistrationsFor(self, cfg, default=None):
@@ -117,8 +212,24 @@
pass
+class BBBRegistrationManager(object):
+
+ def _SampleContainer__data(self):
+ from BTrees.OOBTree import OOBTree
+ if '_data' in self.__dict__:
+ return OOBTree(self._data)
+ _SampleContainer__data = Lazy(_SampleContainer__data)
+
+
class BBBRegisterableContainer(object):
+ def registrationManager(self):
+ from zope.app.component.registration import RegistrationManager
+ for obj in self.values():
+ if isinstance(obj, RegistrationManager):
+ return obj
+ registrationManager = Lazy(registrationManager)
+
def getRegistrationManager(self):
return self.registrationManager
Modified: Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/site.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/site.py 2005-02-12 22:40:27 UTC (rev 29128)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/site.py 2005-02-13 02:16:56 UTC (rev 29129)
@@ -17,11 +17,38 @@
"""
__docformat__ = "reStructuredText"
from zope.component.bbb.service import IService
+from zope.cachedescriptors import property
+from zope.app import zapi
import registration
+
+class BBBSiteManagerContainer(object):
+
+ def _sm(self):
+ if '_ServiceManagerContainer__sm' in self.__dict__:
+ return self._ServiceManagerContainer__sm
+ elif '_SiteManagerContainer__sm' in self.__dict__:
+ return self._SiteManagerContainer__sm
+ else:
+ return None
+ _sm = property.Lazy(_sm)
+
+
class BBBSiteManager(object):
+ def utilities(self):
+ gsm = zapi.getGlobalSiteManager()
+ from zope.app.component.site import LocalUtilityRegistry
+ return LocalUtilityRegistry(gsm.utilities)
+ utilities = property.Lazy(utilities)
+
+ def adapters(self):
+ gsm = zapi.getGlobalSiteManager()
+ from zope.app.component import adapter
+ return adapter.LocalAdapterRegistry(gsm.adapters)
+ adapters = property.Lazy(adapters)
+
def queryRegistrationsFor(self, cfg, default=None):
return self.queryRegistrations(cfg.name, default)
@@ -73,3 +100,9 @@
# Ignore, hoping that noone uses this horrible method
return []
+class BBBUtilityRegistration(object):
+
+ def provided(self):
+ if 'interface' in self.__dict__:
+ return self.interface
+ provided = property.Lazy(provided)
Modified: Zope3/branches/srichter-blow-services/src/zope/app/component/registration.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/registration.py 2005-02-12 22:40:27 UTC (rev 29128)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/registration.py 2005-02-13 02:16:56 UTC (rev 29129)
@@ -94,7 +94,8 @@
'This method must be implemented by each specific regstration.'
-class ComponentRegistration(SimpleRegistration):
+class ComponentRegistration(bbb.registration.BBBComponentRegistration,
+ SimpleRegistration):
"""Component registration.
Subclasses should define a getInterface() method returning the interface
@@ -103,7 +104,9 @@
implements(interfaces.IComponentRegistration)
def __init__(self, component, permission=None):
- self.component = component
+ # BBB: Will go away in 3.3.
+ super(ComponentRegistration, self).__init__(component, permission)
+ # self.component = component
if permission == 'zope.Public':
permission = CheckerPublic
self.permission = permission
@@ -205,7 +208,8 @@
reg.component is self.registerable)]
-class RegistrationManager(BTreeContainer):
+class RegistrationManager(bbb.registration.BBBRegistrationManager,
+ BTreeContainer):
"""Registration manager
Manages registrations within a package.
@@ -232,7 +236,7 @@
return chosenName
-class RegisterableContainer(object):
+class RegisterableContainer(bbb.registration.BBBRegisterableContainer):
"""Mix-in to implement `IRegisterableContainer`"""
implements(interfaces.IRegisterableContainer,
interfaces.IRegisterableContainerContaining)
Modified: Zope3/branches/srichter-blow-services/src/zope/app/component/site.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/site.py 2005-02-12 22:40:27 UTC (rev 29128)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/site.py 2005-02-13 02:16:56 UTC (rev 29129)
@@ -42,6 +42,8 @@
from zope.app.filerepresentation.interfaces import IDirectoryFactory
from zope.app.traversing.interfaces import IContainmentRoot
+# Goes away in 3.3.
+import bbb.site
class SiteManagementFolder(registration.RegisterableContainer,
BTreeContainer):
@@ -58,7 +60,7 @@
return SiteManagementFolder()
-class SiteManagerContainer(Contained):
+class SiteManagerContainer(bbb.site.BBBSiteManagerContainer, Contained):
"""Implement access to the site manager (++etc++site).
This is a mix-in that implements the IPossibleSite
@@ -66,11 +68,12 @@
"""
zope.interface.implements(interfaces.IPossibleSite)
- __sm = None
+ # BBB: Deactive in 3.3 again. Now provided by BBBSiteManagerContainer
+ #_sm = None
def getSiteManager(self):
- if self.__sm is not None:
- return self.__sm
+ if self._sm is not None:
+ return self._sm
else:
raise ComponentLookupError('no site manager defined')
@@ -79,7 +82,7 @@
raise TypeError("Already a site")
if zope.component.interfaces.ISiteManager.providedBy(sm):
- self.__sm = sm
+ self._sm = sm
sm.__name__ = '++etc++site'
sm.__parent__ = self
else:
@@ -122,6 +125,7 @@
class LocalSiteManager(BTreeContainer,
+ bbb.site.BBBSiteManager,
zope.component.site.SiteManager):
"""Local Site Manager implementation"""
zope.interface.implements(
@@ -246,7 +250,8 @@
return zapi.getSiteManager(self)
-class UtilityRegistration(registration.ComponentRegistration):
+class UtilityRegistration(bbb.site.BBBUtilityRegistration,
+ registration.ComponentRegistration):
"""Utility component registration for persistent components
This registration configures persistent components in packages to
Modified: Zope3/branches/srichter-blow-services/src/zope/app/pluggableauth/__init__.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/pluggableauth/__init__.py 2005-02-12 22:40:27 UTC (rev 29128)
+++ Zope3/branches/srichter-blow-services/src/zope/app/pluggableauth/__init__.py 2005-02-13 02:16:56 UTC (rev 29129)
@@ -31,6 +31,7 @@
from zope.interface import implements
from zope.component.interfaces import IViewFactory
+from zope.deprecation import deprecated
from zope.app import zapi
from zope.app.component import queryNextUtility
@@ -189,6 +190,14 @@
del self[id]
+# BBB: Gone in 3.3.
+PluggableAuthenticationService = PluggableAuthentication
+
+deprecated('PluggableAuthenticationService',
+ 'The pluggable authentication service has been deprecated in '
+ 'favor of authentication (aka PAS). This reference will be gone in '
+ 'Zope X3.3.')
+
def PluggableAuthenticationAddSubscriber(self, event):
r"""Generates an earmark if one is not provided.
Modified: Zope3/branches/srichter-blow-services/src/zope/app/site/interfaces.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/site/interfaces.py 2005-02-12 22:40:27 UTC (rev 29128)
+++ Zope3/branches/srichter-blow-services/src/zope/app/site/interfaces.py 2005-02-13 02:16:56 UTC (rev 29129)
@@ -15,11 +15,12 @@
$Id: interfaces.py 27514 2004-09-13 15:54:05Z fdrake $
"""
+import zope.schema
from zope.deprecation import deprecated
from zope.interface import Interface
+
from zope.app.component.interfaces import registration
from zope.app.container.interfaces import IContainer
-
from zope.app.component.interfaces import IPossibleSite, ISite
from zope.app.component.interfaces import ILocalSiteManager
from zope.app.component.interfaces import ISiteManagementFolder
@@ -95,6 +96,29 @@
'Now that services are gone, we do not need the binding support. '
'The reference will be gone in X3.3.')
+class IServiceRegistration(registration.IComponentRegistration):
+ """Service Registration
+
+ Service registrations are dependent on the components that they
+ configure. They register themselves as component dependents.
+
+ The name of a service registration is used to determine the service
+ type.
+ """
+
+ name = zope.schema.TextLine(
+ title=u"Name",
+ description=u"The name that is registered",
+ readonly=True,
+ # Don't allow empty or missing name:
+ required=True,
+ min_length=1,
+ )
+
+deprecated('IServiceRegistration',
+ 'The concept of services has been removed. Use utilities instead. '
+ 'The reference will be gone in X3.3.')
+
class ISiteManagementFolders(IContainer, IComponentManager):
"""A collection of ISiteManagementFolder objects.
Modified: Zope3/branches/srichter-blow-services/src/zope/app/site/service.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/site/service.py 2005-02-12 22:40:27 UTC (rev 29128)
+++ Zope3/branches/srichter-blow-services/src/zope/app/site/service.py 2005-02-13 02:16:56 UTC (rev 29129)
@@ -16,12 +16,15 @@
$Id$
"""
__docformat__ = "reStructuredText"
+import zope.interface
from zope.deprecation import deprecated
-from zope.app.component.site import SiteManager, UtilityRegistration
+from zope.app.component.site import LocalSiteManager, UtilityRegistration
from zope.app.component.interfaces.registration import \
IRegisterableContainerContaining as IRegisterableContainerContainer
+from interfaces import IServiceRegistration
+
deprecated(('SiteManager', 'UtilityRegistration'),
'This class has been moved to zope.app.component.site. '
'The reference will be gone in X3.3.')
@@ -31,9 +34,11 @@
'and been renamed to IRegisterableContainerContaining. '
'The reference will be gone in X3.3.')
-ServiceManager = SiteManager
+ServiceManager = LocalSiteManager
+SiteManager = LocalSiteManager
-ServiceRegistration = UtilityRegistration
+class ServiceRegistration(UtilityRegistration):
+ zope.interface.implements(IServiceRegistration)
deprecated(('ServiceManager', 'ServiceRegistration'),
'The concept of services has been removed. Use utilities instead. '
Modified: Zope3/branches/srichter-blow-services/src/zope/app/utility/utility.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/utility/utility.py 2005-02-12 22:40:27 UTC (rev 29128)
+++ Zope3/branches/srichter-blow-services/src/zope/app/utility/utility.py 2005-02-13 02:16:56 UTC (rev 29129)
@@ -16,10 +16,13 @@
$Id: utility.py 28662 2004-12-21 03:29:21Z srichter $
"""
+from persistent import Persistent
from zope.deprecation import deprecated
from zope.app.component import getNextUtility, queryNextUtility
from zope.app.component.testing import testingNextUtility
+from zope.app.component.site import UtilityRegistration
+from zope.app.container.contained import Contained
deprecated(('getNextUtility', 'queryNextUtility'),
'This function has been moved to zope.app.component. '
@@ -29,8 +32,12 @@
'This function has been moved to zope.app.component.testing. '
'The reference will be gone in X3.3.')
+deprecated('UtilityRegistration',
+ 'This class has been moved to zope.app.component.site. '
+ 'The reference will be gone in X3.3.')
-class LocalUtilityService(object):
+
+class LocalUtilityService(Persistent, Contained):
# I really hope noone noone is using this class manually!
pass
Modified: Zope3/branches/srichter-blow-services/src/zope/app/zopeappgenerations/evolve1.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/zopeappgenerations/evolve1.py 2005-02-12 22:40:27 UTC (rev 29128)
+++ Zope3/branches/srichter-blow-services/src/zope/app/zopeappgenerations/evolve1.py 2005-02-13 02:16:56 UTC (rev 29129)
@@ -16,18 +16,23 @@
$Id$
"""
__docformat__ = "reStructuredText"
+from zope.component.bbb.service import IService
+
from zope.app import zapi
+from zope.app.component.interfaces.registration import IRegistrationManager
+from zope.app.component.interfaces.registration import IRegisterableContainer
from zope.app.error.error import ErrorReportingUtility
from zope.app.error.interfaces import IErrorReportingUtility
-from zope.app.generations.utility import findObjectsProviding
from zope.app.principalannotation import PrincipalAnnotationUtility
from zope.app.principalannotation.interfaces import IPrincipalAnnotationUtility
-from zope.app.registration.interfaces import IComponentRegistration
-from zope.app.registration.interfaces import ActiveStatus, UnregisteredStatus
+from zope.app.component.interfaces.registration import ActiveStatus
+from zope.app.component.interfaces.registration import InactiveStatus
from zope.app.site.interfaces import ISite, IServiceRegistration
from zope.app.utility import UtilityRegistration
from zope.app.zopeappgenerations import getRootFolder
+from zope.app.generations.utility import findObjectsProviding
+
generation = 1
def evolve(context):
@@ -44,83 +49,145 @@
- Component-based registrations used to keep track of their components via
the component's path. Now it stores the component directly. All
registrations are updated to this new format.
+
+ - Conerts all service registrations to utility registrations providing
+ IService, which is the method used to simulate the old service API.
+
+ - Remove 'RegistrationManager' object from all site management folders.
+
+ - Remove all local adapter and utility service instances.
"""
root = getRootFolder(context)
- # Fix up Principal Annotation Service --> Utility
- # We do this by simply removing old Principal Annotation Services and their
- # registrations and then add a new Principal Annotation utility.
for site in findObjectsProviding(root, ISite):
- for reg in findObjectsProviding(site.getSiteManager(),
- IServiceRegistration):
-
- if reg.name == 'PrincipalAnnotation':
- ann = reg.component
- # Set the registration to unregistered and then delete it
- reg.status = UnregisteredStatus
- del zapi.getParent(reg)[zapi.name(reg)]
- # Get the instance dictionary from the old principal
- # annotation service and then delete the service
- props = ann.__dict__
- name = zapi.name(ann)
- folder = zapi.getParent(ann)
- del folder[name]
+ sm = site.getSiteManager()
+ # Remove old registration manager instances
+ for rm in findObjectsProviding(sm, IRegistrationManager):
+ # Make sure that we called the new registration manager
+ # which will retrieve the old one, if necessary
+ zapi.getParent(rm).registrationManager = rm
- # Only add a new principal annotation utility, if there is none.
- utils = [obj for obj in folder.values()
- if isinstance(obj, PrincipalAnnotationUtility)]
- if len(utils) == 0:
- # Create the principal annotation utility and set its
- # properties
- utility = PrincipalAnnotationUtility()
- utility.__dict__.update(props)
- folder[name] = utility
- # Register the utility and set the registration active
- reg = UtilityRegistration('', IPrincipalAnnotationUtility,
- utility)
- reg_manager = folder.getRegistrationManager()
- key = reg_manager.addRegistration(reg)
- reg_manager[key].status = ActiveStatus
+ # Do a hard core delete, because I want no whining and complaining
+ container = zapi.getParent(rm)
+ del container._SampleContainer__data[zapi.getName(rm)]
+ # Make sure the new registration manager has the correct name:
+ rm.__name__ = '++registrations++'
+ rm.__parent__ = container
+ for reg_container in findObjectsProviding(sm, IRegisterableContainer):
+ manager = reg_container.registrationManager
+
+ # Iterate through each registration and fix it up.
+ for reg in tuple(manager.values()):
+
+ # Regardless of registration type, we want to convert the
+ # component path to component
+ if ('_BBB_componentPath' in reg.__dict__ and
+ reg._BBB_componentPath is not None):
+
+ reg.component = reg.getComponent()
+ del reg.__dict__['_BBB_componentPath']
+
+ # Fixup and convert service registrations
+ if IServiceRegistration.providedBy(reg):
+ if reg.name == 'ErrorLogging':
+ fixupErrorLogging(reg_container, reg)
+
+ elif reg.name == 'PrincipalAnnotation':
+ fixupPrincipalAnnotation(reg_container, reg)
+
+ elif reg.name in ('Utilities', 'Adapters'):
+ # Delete the registration
+ reg.status = InactiveStatus
+ del manager[zapi.name(reg)]
+ # Delete the component
+ c = reg.component
+ del zapi.getParent(c)[zapi.name(c)]
+
+ else:
+ # Handle all outstanding service registrations
+ # Create a new utility registration
+ new_reg = UtilityRegistration(reg.name, IService,
+ reg.component)
+ manager.addRegistration(new_reg)
+ new_reg.status = ActiveStatus
+ # Delete the old registration
+ reg.status = InactiveStatus
+ del manager[zapi.getName(reg)]
+
+ # Fixup utility registrations
+ else:
+ # Getting the provided interface converts the utility
+ # registration automatically from 'interface' -> 'provided'
+ reg.provided
+ # Now let's reactivate the utility, so it will be
+ # available within the new framework
+ orig = reg.status
+ reg.status = InactiveStatus
+ reg.status = orig
+
+
+def fixupErrorLogging(reg_container, reg):
# Fix up Error Reporting Service --> Utility
# We do this by simply removing old Error Reporting Services and their
# registrations and then add a new error reporting utility.
- for site in findObjectsProviding(root, ISite):
- for reg in findObjectsProviding(site.getSiteManager(),
- IServiceRegistration):
-
- if reg.name == 'ErrorLogging':
- errors = reg.component
- # Set the registration to unregistered and then delete it
- reg.status = UnregisteredStatus
- del zapi.getParent(reg)[zapi.name(reg)]
- # Get the properties from the old error reporting service and
- # delete it
- props = errors.getProperties()
- folder = zapi.getParent(errors)
- del folder[zapi.name(errors)]
- # Only add a new error reporting utility, if there is none.
- if 'ErrorReporting' not in folder:
- # Create the error reporting utility and set its properties
- utility = ErrorReportingUtility()
- utility.setProperties(**props)
- folder['ErrorReporting'] = utility
- # Register the utility and set the registration active
- reg = UtilityRegistration('', IErrorReportingUtility,
- utility)
- reg_manager = folder.getRegistrationManager()
- key = reg_manager.addRegistration(reg)
- reg_manager[key].status = ActiveStatus
+ errors = reg.component
+ # Set the registration to unregistered and then delete it
+ reg.status = InactiveStatus
+ del zapi.getParent(reg)[zapi.name(reg)]
+ # Get the properties from the old error reporting service and
+ # delete it
+ props = errors.getProperties()
+ folder = zapi.getParent(errors)
+ del folder._SampleContainer__data[zapi.name(errors)]
+
+ # Only add a new error reporting utility, if there is none.
+ if 'ErrorReporting' not in folder:
+ # Create the error reporting utility and set its properties
+ utility = ErrorReportingUtility()
+ utility.setProperties(**props)
+ folder['ErrorReporting'] = utility
+ # Register the utility and set the registration active
+ reg = UtilityRegistration('', IErrorReportingUtility, utility)
+ reg_manager = folder.registrationManager
+ key = reg_manager.addRegistration(reg)
+ reg_manager[key].status = ActiveStatus
+ else:
+ # If there is one, then at least move the data
+ folder['ErrorReporting'].__dict__.update(props)
- # Fix up registration `componentPath` --> `component`
- sites = findObjectsProviding(root, ISite)
- for site in sites:
- registrations = findObjectsProviding(site.getSiteManager(),
- IComponentRegistration)
- for reg in registrations:
- if reg._BBB_componentPath is not None:
- reg.component = reg.getComponent()
+def fixupPrincipalAnnotation(reg_container, reg):
+ # Fix up Principal Annotation Service --> Utility
+ ann = reg.component
+ # Set the registration to inactive and then delete it
+ reg.status = InactiveStatus
+ del zapi.getParent(reg)[zapi.name(reg)]
+ # Get the instance dictionary from the old principal
+ # annotation service and then delete the service
+ props = ann.__dict__
+ name = zapi.name(ann)
+ folder = zapi.getParent(ann)
+ del folder._SampleContainer__data[name]
+
+ # Only add a new principal annotation utility, if there is none.
+ utils = [obj for obj in folder.values()
+ if IPrincipalAnnotationUtility.providedBy(obj)]
+ if len(utils) == 0:
+ # Create the principal annotation utility and set its
+ # properties
+ utility = PrincipalAnnotationUtility()
+ utility.__dict__.update(props)
+ folder[name] = utility
+ # Register the utility and set the registration active
+ reg = UtilityRegistration('', IPrincipalAnnotationUtility,
+ utility)
+ reg_manager = folder.getRegistrationManager()
+ key = reg_manager.addRegistration(reg)
+ reg_manager[key].status = ActiveStatus
+ else:
+ # If there is one, then at least move the data
+ utils[0].__dict__.update(props)
Modified: Zope3/branches/srichter-blow-services/src/zope/component/bbb/utility.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/component/bbb/utility.py 2005-02-12 22:40:27 UTC (rev 29128)
+++ Zope3/branches/srichter-blow-services/src/zope/component/bbb/utility.py 2005-02-13 02:16:56 UTC (rev 29129)
@@ -37,6 +37,7 @@
"""
def __init__(self, sitemanager=None):
+ self.__parent__ = None
if sitemanager is None:
from zope.component.site import GlobalSiteManager
sitemanager = GlobalSiteManager()
More information about the Zope3-Checkins
mailing list