[Zope3-checkins] SVN: Zope3/branches/jim-adapter/src/zope/app/
Removed use of deprecated registration APIs.
Jim Fulton
jim at zope.com
Thu Apr 20 07:33:15 EDT 2006
Log message for revision 67170:
Removed use of deprecated registration APIs.
Changed:
U Zope3/branches/jim-adapter/src/zope/app/appsetup/bootstrap.py
U Zope3/branches/jim-adapter/src/zope/app/schema/tests/test_interfaceutility.py
U Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/browser/ftests/test_contentworkflowsmanager.py
U Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/tests/test_contentworkflow.py
-=-
Modified: Zope3/branches/jim-adapter/src/zope/app/appsetup/bootstrap.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/appsetup/bootstrap.py 2006-04-20 11:33:12 UTC (rev 67169)
+++ Zope3/branches/jim-adapter/src/zope/app/appsetup/bootstrap.py 2006-04-20 11:33:14 UTC (rev 67170)
@@ -23,6 +23,7 @@
import logging
import warnings
+import zope.deprecation
import zope.event
from zope.security.management import getSecurityPolicy
from zope.security.simplepolicies import ParanoidSecurityPolicy
@@ -35,7 +36,8 @@
from zope.app.publication.zopepublication import ZopePublication
from zope.app.appsetup import interfaces
-def ensureObject(root_folder, object_name, object_type, object_factory, asObject=False):
+def ensureObject(root_folder, object_name, object_type, object_factory,
+ asObject=False):
"""Check that there's a basic object in the site
manager. If not, add one.
@@ -65,7 +67,9 @@
Returns the name added or ``None`` if nothing was added.
"""
if not asObject:
- warnings.warn("asObject=False is deprecated", DeprecationWarning, 2)
+ warnings.warn("asObject=False is deprecated and will not be "
+ "supported after Zope 3.5",
+ DeprecationWarning, 2)
sm = root_folder.getSiteManager()
utils = [reg for reg in sm.registeredUtilities()
@@ -79,26 +83,31 @@
return None
def addConfigureUtility(
- root_folder, interface, utility_type, utility_factory, name='', asObject=False, **kw):
+ root_folder, interface, utility_type, utility_factory, name='',
+ asObject=False, **kw):
"""Add and configure a utility to the root folder."""
if not asObject:
- warnings.warn("asObject=False is deprecated", DeprecationWarning, 2)
+ warnings.warn("asObject=False is deprecated and will not be "
+ "supported after Zope 3.5", DeprecationWarning, 2)
- utility = addUtility(root_folder, utility_type, utility_factory, True, **kw)
- configureUtility(root_folder, interface, utility_type, name, utility.__name__)
+ utility = addUtility(root_folder, utility_type, utility_factory, True,
+ **kw)
+ root_folder.getSiteManager().registerUtility(utility, interface, name)
if asObject:
return utility
else:
return utility.__name__
-def addUtility(root_folder, utility_type, utility_factory, asObject=False, **kw):
+def addUtility(root_folder, utility_type, utility_factory,
+ asObject=False, **kw):
""" Add a Utility to the root folder's site manager.
The utility is added to the default package and activated.
"""
if not asObject:
- warnings.warn("asObject=False is deprecated", DeprecationWarning, 2)
+ warnings.warn("asObject=False is deprecated and will not be "
+ "supported after Zope 3.5", DeprecationWarning, 2)
package = getSiteManagerDefault(root_folder)
chooser = INameChooser(package)
@@ -119,15 +128,21 @@
else:
return name
+ at zope.deprecation.deprecate(
+ 'configureUtility is deprecated and will be removed in Zope 3.5. '
+ 'The registration APIs are simple enough now that this just makes things '
+ 'mor complicated,')
def configureUtility(
root_folder, interface, utility_type, name, folder_name,
initial_status=u'Active'):
"""Configure a utility in the root folder."""
+ # folder name is the name of the utility in the default folder. Sheesh
+ assert initial_status == u'Active'
package = getSiteManagerDefault(root_folder)
- registration_manager = package.registrationManager
- reg = site.UtilityRegistration(name, interface, package[folder_name])
- key = registration_manager.addRegistration(reg)
- reg.status = initial_status
+ root_folder.getSiteManager().registerUtility(
+ package[folder_name],
+ interface, name,
+ )
def getSiteManagerDefault(root_folder):
package = traverse(root_folder.getSiteManager(), 'default')
Modified: Zope3/branches/jim-adapter/src/zope/app/schema/tests/test_interfaceutility.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/schema/tests/test_interfaceutility.py 2006-04-20 11:33:12 UTC (rev 67169)
+++ Zope3/branches/jim-adapter/src/zope/app/schema/tests/test_interfaceutility.py 2006-04-20 11:33:14 UTC (rev 67170)
@@ -24,11 +24,7 @@
from zope.component.interface import getInterface, searchInterface
from zope.traversing.api import traverse
-from zope.app.component.interfaces import ILocalUtility
from zope.app.component.testing import PlacefulSetup
-from zope.app.component.interfaces.registration import ActiveStatus
-from zope.app.component.interfaces.registration import InactiveStatus
-from zope.app.component.interfaces.registration import IRegistered
from zope.app.container.contained import Contained
from zope.app.dependable.interfaces import IDependable
from zope.app.testing import setup
@@ -36,31 +32,17 @@
class IBaz(Interface): pass
class Baz(object):
- # We implement IRegistered and IDependable directly to
+ # We implement IDependable directly to
# depend as little as possible on other infrastructure.
- implements(IBaz, ILocalUtility, IRegistered, IDependable)
+ implements(IBaz, IDependable)
def __init__(self, name):
self.name = name
- self._usages = []
self._dependents = []
def foo(self):
return 'foo ' + self.name
- def addUsage(self, location):
- "See zope.app.registration.interfaces.IRegistered"
- if location not in self._usages:
- self._usages.append(location)
-
- def removeUsage(self, location):
- "See zope.app.registration.interfaces.IRegistered"
- self._usages.remove(location)
-
- def usages(self):
- "See zope.app.registration.interfaces.IRegistered"
- return self._usages
-
def addDependent(self, location):
"See zope.app.dependable.interfaces.IDependable"
if location not in self._dependents:
@@ -128,17 +110,12 @@
gsm = zope.component.getGlobalSiteManager()
gsm.registerUtility(foo, IInterface, name="bob")
- gsm.registerUtility(bar, ILocalUtility)
gsm.registerUtility(baz, IBaz)
iface_utilities = gsm.getUtilitiesFor(IInterface)
ifaces = [iface for (name, iface) in iface_utilities]
self.assertEqual(ifaces, [(foo)])
- iface_utilities = gsm.getUtilitiesFor(ILocalUtility)
- ifaces = [iface for (name, iface) in iface_utilities]
- self.assertEqual(ifaces, [(bar)])
-
iface_utilities = gsm.getUtilitiesFor(IBaz)
ifaces = [iface for (name, iface) in iface_utilities]
self.assertEqual(ifaces, [(baz)])
Modified: Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/browser/ftests/test_contentworkflowsmanager.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/browser/ftests/test_contentworkflowsmanager.py 2006-04-20 11:33:12 UTC (rev 67169)
+++ Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/browser/ftests/test_contentworkflowsmanager.py 2006-04-20 11:33:14 UTC (rev 67170)
@@ -25,8 +25,6 @@
from zope.app import zapi
from zope.app.testing.functional import BrowserTestCase
from zope.app.testing.setup import addUtility
-from zope.app.component.interfaces.registration import ActiveStatus
-from zope.app.component.site import UtilityRegistration
from zope.app.workflow.stateful.definition import StatefulProcessDefinition
from zope.app.workflow.stateful.interfaces import IStatefulProcessDefinition,\
@@ -56,14 +54,8 @@
'ContentWorkflowsManager',
'new_value': 'mgr' })
- root = self.getRootFolder()
- default = zapi.traverse(root, '/++etc++site/default')
- rm = default.registrationManager
- registration = UtilityRegistration(
- 'cwm', IContentWorkflowsManager,
- zapi.traverse(root, self.basepath+'/mgr'))
- pd_id = rm.addRegistration(registration)
- zapi.traverse(rm, pd_id).status = ActiveStatus
+ sm.registerUtility(sm['default']['mgr'],
+ IContentWorkflowsManager, 'cwm')
def test_registry(self):
response = self.publish(
Modified: Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/tests/test_contentworkflow.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/tests/test_contentworkflow.py 2006-04-20 11:33:12 UTC (rev 67169)
+++ Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/tests/test_contentworkflow.py 2006-04-20 11:33:14 UTC (rev 67170)
@@ -26,9 +26,6 @@
from zope.app import zapi
from zope.app.container.contained import Contained
-from zope.app.component.site import UtilityRegistration
-from zope.app.component.interfaces import ILocalUtility
-from zope.app.component.interfaces.registration import ActiveStatus
from zope.app.workflow.interfaces import IProcessDefinition
from zope.app.workflow.interfaces import IProcessInstanceContainerAdaptable
@@ -44,7 +41,7 @@
# define and create dummy ProcessDefinition (PD) for tests
class DummyProcessDefinition(Contained):
- implements(IProcessDefinition, IAttributeAnnotatable, ILocalUtility)
+ implements(IProcessDefinition, IAttributeAnnotatable)
def __init__(self, n):
self.n = n
More information about the Zope3-Checkins
mailing list