[CMF-checkins] SVN: CMF/branches/jens_tools_as_utilities/CMF - checkpoint checkin with some more tools converted

Jens Vagelpohl jens at dataflake.org
Tue Dec 26 12:52:16 EST 2006


Log message for revision 71653:
  - checkpoint checkin with some more tools converted
  

Changed:
  U   CMF/branches/jens_tools_as_utilities/CMFCalendar/tests/test_Calendar.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/ActionInformation.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/CachingPolicyManager.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/CookieCrumbler.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/DiscussionTool.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/Expression.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/MemberDataTool.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/MembershipTool.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/RegistrationTool.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/SkinsTool.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/cookieauth.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_cookieauth.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_ActionInformation.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_ActionProviderBase.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_ActionsTool.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_DynamicType.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_Expression.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_MemberDataTool.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_MembershipTool.py
  U   CMF/branches/jens_tools_as_utilities/CMFCore/utils.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/DefaultWorkflow.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/DiscussionItem.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/DiscussionTool.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/DublinCore.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/MembershipTool.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/RegistrationTool.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/skins/zpt_generic/getMainGlobals.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/skins/zpt_generic/news_box.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/skins/zpt_generic/password_email.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/skins/zpt_generic/registered_email.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/tests/RegistrationTool.txt
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_DiscussionReply.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_DiscussionTool.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_Discussions.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_DublinCore.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_Image.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_Portal.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_RegistrationTool.py
  U   CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_join.py

-=-
Modified: CMF/branches/jens_tools_as_utilities/CMFCalendar/tests/test_Calendar.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCalendar/tests/test_Calendar.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCalendar/tests/test_Calendar.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -27,7 +27,9 @@
 from AccessControl.User import UnrestrictedUser
 from DateTime import DateTime
 
+from Products.CMFCore.interfaces import IActionsTool
 from Products.CMFCore.interfaces import ICatalogTool
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFCalendar.testing import FunctionalLayer
 
 
@@ -118,7 +120,9 @@
 
         # register utilities
         sm = getSiteManager()
+        sm.registerUtility(self.app.site.portal_actions, IActionsTool)
         sm.registerUtility(self.app.site.portal_catalog, ICatalogTool)
+        sm.registerUtility(self.app.site.portal_membership, IMembershipTool)
 
     def _testURL(self, url, params=None):
         obj = self.app.site.restrictedTraverse(url)

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/ActionInformation.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/ActionInformation.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/ActionInformation.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -24,6 +24,8 @@
 from OFS.OrderedFolder import OrderedFolder
 from OFS.PropertyManager import PropertyManager
 from OFS.SimpleItem import SimpleItem
+
+from zope.component import getUtility
 from zope.i18nmessageid import Message
 from zope.interface import implements
 
@@ -31,11 +33,11 @@
 from interfaces import IAction
 from interfaces import IActionCategory
 from interfaces import IActionInfo
+from interfaces import IMembershipTool
 from interfaces.portal_actions import ActionInfo as z2IActionInfo
 from permissions import View
 from utils import _checkPermission
 from utils import _wwwdir
-from utils import getToolByName
 
 
 _unchanged = [] # marker
@@ -502,7 +504,7 @@
 
     def __init__( self, tool, folder, object=None ):
         self.portal = portal = aq_parent(aq_inner(tool))
-        membership = getToolByName(tool, 'portal_membership')
+        membership = getUtility(IMembershipTool)
         self.isAnonymous = membership.isAnonymousUser()
         self.user_id = membership.getAuthenticatedMember().getId()
         self.portal_url = portal.absolute_url()

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/CachingPolicyManager.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/CachingPolicyManager.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/CachingPolicyManager.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -29,7 +29,9 @@
 from OFS.SimpleItem import SimpleItem
 from Products.PageTemplates.Expressions import getEngine
 from Products.PageTemplates.Expressions import SecureModuleImporter
+
 from zope.app.container.interfaces import IObjectMovedEvent
+from zope.component import queryUtility
 from zope.interface import implements
 
 from permissions import ManagePortal
@@ -37,12 +39,12 @@
 from Expression import Expression
 from interfaces import ICachingPolicy
 from interfaces import ICachingPolicyManager
+from interfaces import IMembershipTool
 from interfaces.CachingPolicyManager \
         import CachingPolicyManager as z2ICachingPolicyManager
 from utils import _dtmldir
 from utils import _setCacheHeaders
 from utils import _ViewEmulator
-from utils import getToolByName
 from utils import registerToolInterface
 
 # This is lame :(
@@ -62,7 +64,7 @@
         Construct an expression context for TALES expressions,
         for use by CachingPolicy objects.
     """
-    pm = getToolByName( content, 'portal_membership', None )
+    pm = queryUtility(IMembershipTool)
     if not pm or pm.isAnonymousUser():
         member = None
     else:

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/CookieCrumbler.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/CookieCrumbler.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/CookieCrumbler.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -32,6 +32,7 @@
 from OFS.interfaces import IObjectWillBeMovedEvent
 
 from interfaces import ICookieCrumbler
+from utils import registerToolInterface
 
 
 # Constants.
@@ -382,6 +383,7 @@
         return id
 
 Globals.InitializeClass(CookieCrumbler)
+registerToolInterface('cookie_authentication', ICookieCrumbler)
 
 def handleCookieCrumblerEvent(ob, event):
     """ Event subscriber for (un)registering a CC as a before traverse hook.

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/DiscussionTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/DiscussionTool.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/DiscussionTool.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -29,6 +29,7 @@
 from permissions import ReplyToItem
 from permissions import View
 from interfaces import ICatalogTool
+from interfaces import IMembershipTool
 from interfaces import IOldstyleDiscussable
 from interfaces import IOldstyleDiscussionTool
 from interfaces.Discussions import OldDiscussable as z2IOldstyleDiscussable
@@ -71,7 +72,7 @@
         # It is not yet clear to me what the correct location for this hook is
 
         # Find the folder designated for replies, creating if missing
-        membershiptool = getToolByName(self.content, 'portal_membership')
+        membershiptool = getUtility(IMembershipTool)
         home = membershiptool.getHomeFolder()
         if not hasattr(home, 'Correspondence'):
             home.manage_addPortalFolder('Correspondence')

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/Expression.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/Expression.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/Expression.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -19,9 +19,13 @@
 from Acquisition import aq_base, aq_inner, aq_parent
 from Globals import InitializeClass
 from Globals import Persistent
+
+from zope.component import getUtility
+
 from Products.PageTemplates.Expressions import getEngine
 from Products.PageTemplates.Expressions import SecureModuleImporter
 
+from interfaces import IMembershipTool
 from utils import getToolByName
 
 
@@ -87,7 +91,7 @@
     '''
     An expression context provides names for TALES expressions.
     '''
-    pm = getToolByName(portal, 'portal_membership')
+    pm = getUtility(IMembershipTool)
     if object is None:
         object_url = ''
     else:

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/MemberDataTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/MemberDataTool.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/MemberDataTool.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -23,12 +23,15 @@
 from OFS.PropertyManager import PropertyManager
 from OFS.SimpleItem import SimpleItem
 from ZPublisher.Converters import type_converters
+
+from zope.component import getUtility
 from zope.interface import implements
 
 from ActionProviderBase import ActionProviderBase
 from exceptions import BadRequest
 from interfaces import IMemberData
 from interfaces import IMemberDataTool
+from interfaces import IMembershipTool
 from interfaces.portal_memberdata import MemberData as z2IMemberData
 from interfaces.portal_memberdata \
         import portal_memberdata as z2IMemberDataTool
@@ -37,6 +40,7 @@
 from permissions import ViewManagementScreens
 from utils import _dtmldir
 from utils import getToolByName
+from utils import registerToolInterface
 from utils import UniqueObject
 
 
@@ -99,7 +103,7 @@
         Return the number of members stored in the _members
         BTree and some other useful info
         '''
-        membertool   = getToolByName(self, 'portal_membership')
+        membertool   = getUtility(IMembershipTool)
         members      = self._members
         user_list    = membertool.listMemberIds()
         member_list  = members.keys()
@@ -121,7 +125,7 @@
         if not search_param:
             return res
 
-        membership = getToolByName(self, 'portal_membership')
+        membership = getUtility(IMembershipTool)
 
         if len(attributes) == 0:
             attributes = ('id', 'email')
@@ -157,7 +161,7 @@
         if search_param == 'username':
             search_param = 'id'
 
-        mtool   = getToolByName(self, 'portal_membership')
+        mtool   = getUtility(IMembershipTool)
 
         for member_id in self._members.keys():
 
@@ -179,7 +183,7 @@
     def pruneMemberDataContents(self):
         """ Delete data contents of all members not listet in acl_users.
         """
-        membertool= getToolByName(self, 'portal_membership')
+        membertool= getUtility(IMembershipTool)
         members = self._members
         user_list = membertool.listMemberIds()
 
@@ -235,6 +239,7 @@
             return 0
 
 InitializeClass(MemberDataTool)
+registerToolInterface('portal_memberdata', IMemberDataTool)
 
 
 class CleanupTemp:
@@ -301,7 +306,7 @@
         '''
         if properties is None:
             properties = kw
-        membership = getToolByName(self, 'portal_membership')
+        membership = getUtility(IMembershipTool)
         registration = getToolByName(self, 'portal_registration', None)
         if not membership.isAnonymousUser():
             member = membership.getAuthenticatedMember()

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/MembershipTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/MembershipTool.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/MembershipTool.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -27,11 +27,15 @@
 from Globals import PersistentMapping
 from OFS.Folder import Folder
 from ZODB.POSException import ConflictError
+
+from zope.component import getUtility
+from zope.component import queryUtility
 from zope.interface import implements
 
 from ActionProviderBase import ActionProviderBase
 from exceptions import AccessControl_Unauthorized
 from exceptions import BadRequest
+from interfaces import IMemberDataTool
 from interfaces import IMembershipTool
 from interfaces.portal_membership \
         import portal_membership as z2IMembershipTool
@@ -141,7 +145,7 @@
                         portal_role not in u.roles):
                     u.roles.append(portal_role)
 
-        mdtool = getToolByName(self, 'portal_memberdata', None)
+        mdtool = queryUtility(IMemberDataTool)
         if mdtool is not None:
             try:
                 u = mdtool.wrapUser(u)
@@ -394,7 +398,7 @@
     security.declareProtected(ListPortalMembers, 'searchMembers')
     def searchMembers( self, search_param, search_term ):
         """ Search the membership """
-        md = getToolByName( self, 'portal_memberdata' )
+        md = getUtility(IMemberDataTool)
 
         return md.searchMemberData( search_param, search_term )
 
@@ -496,7 +500,7 @@
                                  'permission for the underlying User Folder.')
 
         # Delete member data in portal_memberdata.
-        mdtool = getToolByName(self, 'portal_memberdata', None)
+        mdtool = queryUtility(IMemberDataTool)
         if mdtool is not None:
             for member_id in member_ids:
                 mdtool.deleteMemberData(member_id)

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/RegistrationTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/RegistrationTool.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/RegistrationTool.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -22,9 +22,12 @@
 from Globals import DTMLFile
 from Globals import InitializeClass
 from OFS.SimpleItem import SimpleItem
+
+from zope.component import getUtility
 from zope.interface import implements
 
 from ActionProviderBase import ActionProviderBase
+from interfaces import IMembershipTool
 from interfaces import IRegistrationTool
 from interfaces.portal_registration \
         import portal_registration as z2IRegistrationTool
@@ -34,7 +37,6 @@
 from utils import _checkPermission
 from utils import _dtmldir
 from utils import _limitGrantedRoles
-from utils import getToolByName
 from utils import Message as _
 from utils import UniqueObject
 
@@ -157,7 +159,7 @@
         # Anyone is always allowed to grant the 'Member' role.
         _limitGrantedRoles(roles, self, ('Member',))
 
-        membership = getToolByName(self, 'portal_membership')
+        membership = getUtility(IMembershipTool)
         membership.addMember(id, password, roles, domains, properties)
 
         member = membership.getMemberById(id)
@@ -172,7 +174,7 @@
             return 0
         if not self._ALLOWED_MEMBER_ID_PATTERN.match( id ):
             return 0
-        membership = getToolByName(self, 'portal_membership')
+        membership = getUtility(IMembershipTool)
         if membership.getMemberById(id) is not None:
             return 0
         return 1

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/SkinsTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/SkinsTool.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/SkinsTool.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -27,12 +27,15 @@
 from OFS.ObjectManager import REPLACEABLE
 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
 from Products.PythonScripts.PythonScript import PythonScript
+
+from zope.component import getUtility
 from zope.interface import implements
 
 from ActionProviderBase import ActionProviderBase
 from DirectoryView import base_ignore
 from DirectoryView import ignore
 from DirectoryView import ignore_re
+from interfaces import IMembershipTool
 from interfaces import ISkinsTool
 from interfaces.portal_skins import portal_skins as z2ISkinsTool
 from permissions import AccessContentsInformation
@@ -305,7 +308,7 @@
     def updateSkinCookie(self):
         """ If needed, updates the skin cookie based on the member preference.
         """
-        mtool = getToolByName(self, 'portal_membership')
+        mtool = getUtility(IMembershipTool)
         utool = getToolByName(self, 'portal_url')
         member = mtool.getAuthenticatedMember()
         if hasattr(aq_base(member), 'portal_skin'):

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/cookieauth.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/cookieauth.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/cookieauth.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -16,6 +16,9 @@
 """
 
 from zope.component import adapts
+from zope.component import getSiteManager
+from zope.component import getUtility
+from zope.component import queryUtility
 
 from Products.GenericSetup.interfaces import ISetupEnviron
 from Products.GenericSetup.utils import exportObjects
@@ -24,7 +27,6 @@
 from Products.GenericSetup.utils import XMLAdapterBase
 
 from Products.CMFCore.interfaces import ICookieCrumbler
-from Products.CMFCore.utils import getToolByName
 
 
 class CookieCrumblerXMLAdapter(XMLAdapterBase, PropertyManagerHelpers):
@@ -61,16 +63,16 @@
 def importCookieCrumbler(context):
     """Import cookie crumbler settings from an XML file.
     """
-    site = context.getSite()
-    tool = getToolByName(site, 'cookie_authentication')
+    sm = getSiteManager(context.getSite())
+    tool = sm.getUtility(ICookieCrumbler)
 
     importObjects(tool, '', context)
 
 def exportCookieCrumbler(context):
     """Export cookie crumbler settings as an XML file.
     """
-    site = context.getSite()
-    tool = getToolByName(site, 'cookie_authentication', None)
+    sm = getSiteManager(context.getSite())
+    tool = queryUtility(ICookieCrumbler)
     if tool is None:
         logger = context.getLogger('cookies')
         logger.info('Nothing to export.')

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_cookieauth.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_cookieauth.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/exportimport/tests/test_cookieauth.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -20,12 +20,15 @@
 
 from OFS.Folder import Folder
 
+from zope.component import getSiteManager
+
 from Products.GenericSetup.testing import BodyAdapterTestCase
 from Products.GenericSetup.tests.common import BaseRegistryTests
 from Products.GenericSetup.tests.common import DummyExportContext
 from Products.GenericSetup.tests.common import DummyImportContext
 
 from Products.CMFCore.CookieCrumbler import CookieCrumbler
+from Products.CMFCore.interfaces import ICookieCrumbler
 from Products.CMFCore.testing import ExportImportZCMLLayer
 
 _COOKIECRUMBLER_BODY = """\
@@ -101,6 +104,9 @@
         self.root.site = Folder(id='site')
         site = self.root.site
         cc = site.cookie_authentication = CookieCrumbler('foo_cookiecrumbler')
+
+        sm = getSiteManager()
+        sm.registerUtility(site.cookie_authentication, ICookieCrumbler)
  
         if use_changed:
             cc.auth_cookie = 'value1'

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_ActionInformation.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_ActionInformation.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_ActionInformation.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -21,8 +21,11 @@
 from OFS.Folder import manage_addFolder
 from Products.PythonScripts.PythonScript import manage_addPythonScript
 
+from zope.component import getSiteManager
+
 from Products.CMFCore.Expression import createExprContext
 from Products.CMFCore.Expression import Expression
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFCore.testing import FunctionalZCMLLayer
 from Products.CMFCore.tests.base.dummy import DummyContent
 from Products.CMFCore.tests.base.dummy import DummySite
@@ -216,7 +219,9 @@
     def setUp(self):
         SecurityTest.setUp(self)
         self.site = DummySite('site').__of__(self.root)
+        sm = getSiteManager()
         self.site._setObject( 'portal_membership', DummyMembershipTool() )
+        sm.registerUtility(self.site.portal_membership, IMembershipTool)
 
     def _makeOne(self, *args, **kw):
         from Products.CMFCore.ActionInformation import ActionInfo
@@ -330,7 +335,9 @@
         root = self.root
         root._setObject('portal', DummyContent('portal', 'url_portal'))
         portal = self.portal = root.portal
+        sm = getSiteManager(portal)
         portal.portal_membership = DummyMembershipTool()
+        sm.registerUtility(portal.portal_membership, IMembershipTool)
         self.folder = DummyContent('foo', 'url_foo')
         self.object = DummyContent('bar', 'url_bar')
 

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_ActionProviderBase.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_ActionProviderBase.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_ActionProviderBase.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -18,6 +18,9 @@
 import unittest
 import Testing
 
+from zope.component import getSiteManager
+
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFCore.tests.base.dummy import DummySite
 from Products.CMFCore.tests.base.dummy import DummyTool
 from Products.CMFCore.tests.base.testcase import SecurityRequestTest
@@ -62,8 +65,10 @@
     def setUp( self ):
         SecurityRequestTest.setUp(self)
         self.site = DummySite('site').__of__(self.root)
+        sm = getSiteManager()
         utool = self.site._setObject( 'portal_url', DummyTool() )
         mtool = self.site._setObject( 'portal_membership', DummyTool() )
+        sm.registerUtility(self.site.portal_membership, IMembershipTool)
 
     def _makeProvider( self, dummy=0 ):
 

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_ActionsTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_ActionsTool.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_ActionsTool.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -18,6 +18,8 @@
 import unittest
 import Testing
 
+from zope.component import getSiteManager
+
 from Products.CMFCore.ActionInformation import Action
 from Products.CMFCore.ActionInformation import ActionCategory
 from Products.CMFCore.ActionInformation import ActionInformation
@@ -25,6 +27,7 @@
 from Products.CMFCore.MembershipTool import MembershipTool
 from Products.CMFCore.tests.base.testcase import SecurityRequestTest
 from Products.CMFCore.URLTool import URLTool
+from Products.CMFCore.interfaces import IMembershipTool
 
 
 class ActionsToolTests(unittest.TestCase):
@@ -107,10 +110,12 @@
         SecurityRequestTest.setUp(self)
 
         root = self.root
+        sm = getSiteManager()
         root._setObject( 'portal_actions', self._makeOne() )
         root._setObject( 'portal_url', URLTool() )
         root._setObject( 'foo', URLTool() )
         root._setObject('portal_membership', MembershipTool())
+        sm.registerUtility(root.portal_membership, IMembershipTool)
         self.tool = root.portal_actions
         self.tool.action_providers = ('portal_actions',)
 

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_DynamicType.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_DynamicType.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_DynamicType.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -22,7 +22,10 @@
 from ZPublisher.BaseRequest import BaseRequest
 from ZPublisher.HTTPResponse import HTTPResponse
 
+from zope.component import getSiteManager
+
 from Products.CMFCore.DynamicType import DynamicType
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFCore.tests.base.dummy import DummyObject
 from Products.CMFCore.tests.base.dummy import DummySite
 from Products.CMFCore.tests.base.dummy import DummyTool
@@ -84,7 +87,9 @@
     def setUp(self):
         SecurityRequestTest.setUp(self)
         self.site = DummySite('site').__of__(self.root)
+        sm = getSiteManager()
         self.site._setObject( 'portal_membership', DummyTool() )
+        sm.registerUtility(self.site.portal_membership, IMembershipTool)
         self.site._setObject( 'portal_types', TypesTool() )
         self.site._setObject( 'portal_url', DummyTool() )
         fti = FTIDATA_CMF15[0].copy()

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_Expression.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_Expression.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_Expression.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -18,9 +18,12 @@
 import unittest
 import Testing
 
+from zope.component import getSiteManager
+
 from Products.CMFCore.ActionInformation import ActionInformation
 from Products.CMFCore.Expression import createExprContext
 from Products.CMFCore.Expression import Expression
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFCore.tests.base.dummy import DummyContent
 from Products.CMFCore.tests.base.dummy import DummyTool as DummyMembershipTool
 from Products.CMFCore.tests.base.testcase import SecurityTest
@@ -46,19 +49,25 @@
                                   , visible=1)
 
     def test_anonymous_ec(self):
+        sm = getSiteManager()
         self.portal.portal_membership = DummyMembershipTool()
+        sm.registerUtility(self.portal.portal_membership, IMembershipTool)
         ec = createExprContext(self.folder, self.portal, self.object)
         member = ec.contexts['member']
         self.failIf(member)
 
     def test_authenticatedUser_ec(self):
+        sm = getSiteManager()
         self.portal.portal_membership = DummyMembershipTool(anon=0)
+        sm.registerUtility(self.portal.portal_membership, IMembershipTool)
         ec = createExprContext(self.folder, self.portal, self.object)
         member = ec.contexts['member']
         self.assertEqual(member.getId(), 'dummy')
 
     def test_ec_context(self):
+        sm = getSiteManager()
         self.portal.portal_membership = DummyMembershipTool()
+        sm.registerUtility(self.portal.portal_membership, IMembershipTool)
         ec = createExprContext(self.folder, self.portal, self.object)
         object = ec.contexts['object']
         portal = ec.contexts['portal']

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_MemberDataTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_MemberDataTool.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_MemberDataTool.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -20,7 +20,12 @@
 
 import Acquisition
 
+from zope.component import getSiteManager
 
+from Products.CMFCore.interfaces import IMemberDataTool
+from Products.CMFCore.interfaces import IMembershipTool
+
+
 class DummyUserFolder(Acquisition.Implicit):
 
     def __init__(self):
@@ -103,8 +108,11 @@
         from OFS.Folder import Folder
         from Products.CMFCore.MembershipTool import MembershipTool
         folder = Folder('test')
+        sm = getSiteManager(folder)
         folder._setObject('portal_memberdata', self._makeOne())
+        sm.registerUtility(folder.portal_memberdata, IMemberDataTool)
         folder._setObject('portal_membership', MembershipTool())
+        sm.registerUtility(folder.portal_membership, IMembershipTool)
         folder._setObject('acl_users', DummyUserFolder())
         tool = folder.portal_memberdata
 

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_MembershipTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_MembershipTool.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_MembershipTool.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -21,8 +21,11 @@
 from AccessControl.SecurityManagement import newSecurityManager
 from OFS.Folder import Folder
 
+from zope.component import getSiteManager
+
 from Products.CMFCore.MemberDataTool import MemberDataTool
 from Products.CMFCore.PortalFolder import PortalFolder
+from Products.CMFCore.interfaces import IMemberDataTool
 from Products.CMFCore.tests.base.dummy import DummySite
 from Products.CMFCore.tests.base.dummy import DummyTool
 from Products.CMFCore.tests.base.dummy import DummyUserFolder
@@ -111,12 +114,14 @@
 
     def test_deleteMembers(self):
         site = self._makeSite()
+        sm = getSiteManager()
         mtool = site.portal_membership
         members = site._setObject( 'Members', PortalFolder('Members') )
         acl_users = site._setObject( 'acl_users', DummyUserFolder() )
         utool = site._setObject( 'portal_url', DummyTool() )
         wtool = site._setObject( 'portal_workflow', DummyTool() )
         mdtool = site._setObject( 'portal_memberdata', MemberDataTool() )
+        sm.registerUtility(mdtool, IMemberDataTool)
         newSecurityManager(None, acl_users.all_powerful_Oz)
 
         self.assertEqual( acl_users.getUserById('user_foo'),

Modified: CMF/branches/jens_tools_as_utilities/CMFCore/utils.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/utils.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/utils.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -49,6 +49,7 @@
 from zope.component import getUtility
 from zope.component import queryUtility
 from zope.component.interfaces import ComponentLookupError
+from zope.dottedname.resolve import resolve as resolve_dotted_name
 from zope.i18nmessageid import MessageFactory
 
 from exceptions import AccessControl_Unauthorized
@@ -113,6 +114,27 @@
             raise AttributeError, name
         return tool
 
+security.declarePublic('getToolByInterfaceName')
+def getToolByInterfaceName(obj, dotted_name, default=_marker):
+    """ Get a tool by its fully-qualified dotted interface path
+
+    This method replaces getToolByName for use in untrusted code.
+    Trusted code should use zope.component.getUtility instead.
+    """
+    try:
+        iface = resolve_dotted_name(dotted_name)
+    except ImportError:
+        if default is _marker:
+            raise ComponentLookupError, dotted_name
+        return default
+
+    try:
+        return getUtility(iface).__of__(obj)
+    except ComponentLookupError:
+        if default is _marker:
+            raise
+        return default
+
 security.declarePublic('cookString')
 def cookString(text):
 

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/DefaultWorkflow.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/DefaultWorkflow.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/DefaultWorkflow.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -22,16 +22,17 @@
 from DateTime import DateTime
 from Globals import InitializeClass
 
+from zope.component import getUtility
 from zope.component import queryUtility
 from zope.interface import implements
 
 from Products.CMFCore.interfaces import ICatalogTool
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFCore.interfaces import IWorkflowDefinition
 from Products.CMFCore.interfaces.portal_workflow \
         import WorkflowDefinition as z2IWorkflowDefinition
 from Products.CMFCore.utils import _checkPermission
 from Products.CMFCore.utils import _modifyPermissionMappings
-from Products.CMFCore.utils import getToolByName
 from Products.CMFCore.utils import SimpleItemWithProperties
 
 from exceptions import AccessControl_Unauthorized
@@ -102,7 +103,7 @@
         content = info.object
         content_url = info.object_url
         content_creator = content.Creator()
-        pm = getToolByName(self, 'portal_membership')
+        pm = getUtility(IMembershipTool)
         current_user = pm.getAuthenticatedMember().getId()
         review_state = self.getReviewStateOf(content)
         actions = []
@@ -206,7 +207,7 @@
             elif review_state == 'private':
                 raise AccessControl_Unauthorized('Already private')
             content_creator = ob.Creator()
-            pm = getToolByName(self, 'portal_membership')
+            pm = getUtility(IMembershipTool)
             current_user = pm.getAuthenticatedMember().getId()
             if (content_creator != current_user) and not allow_review:
                 raise AccessControl_Unauthorized('Not creator or reviewer')
@@ -253,7 +254,7 @@
     security.declarePrivate('setReviewStateOf')
     def setReviewStateOf(self, ob, review_state, action, comment):
         tool = aq_parent(aq_inner(self))
-        pm = getToolByName(self, 'portal_membership')
+        pm = getUtility(IMembershipTool)
         current_user = pm.getAuthenticatedMember().getId()
         status = {
             'actor': current_user,

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/DiscussionItem.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/DiscussionItem.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/DiscussionItem.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -22,16 +22,18 @@
 from Globals import Persistent
 from Globals import PersistentMapping
 from OFS.Traversable import Traversable
+
+from zope.component import getUtility
 from zope.interface import implements
 
 from Products.CMFCore.interfaces import ICallableOpaqueItemEvents
 from Products.CMFCore.interfaces import IDiscussable
 from Products.CMFCore.interfaces import IDiscussionResponse
+from Products.CMFCore.interfaces import IDiscussionTool
 from Products.CMFCore.interfaces.Discussions \
         import Discussable as z2IDiscussable
 from Products.CMFCore.interfaces.Discussions \
         import DiscussionResponse as z2IDiscussionResponse
-from Products.CMFCore.utils import getToolByName
 
 from Document import Document
 from permissions import AccessContentsInformation
@@ -113,7 +115,7 @@
               - We are a nested reply;  in this case, our 'in_reply_to'
                 field will be the ID of the parent DiscussionItem.
         """
-        tool = getToolByName( self, 'portal_discussion' )
+        tool = getUtility(IDiscussionTool)
         talkback = tool.getDiscussionFor( self )
         return talkback._getReplyParent( self.in_reply_to )
 

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/DiscussionTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/DiscussionTool.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/DiscussionTool.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -20,16 +20,20 @@
 from Globals import DTMLFile
 from Globals import InitializeClass
 from OFS.SimpleItem import SimpleItem
+
+from zope.component import getUtility
 from zope.interface import implements
 
 from Products.CMFCore.ActionProviderBase import ActionProviderBase
 from Products.CMFCore.interfaces import IDiscussionResponse
 from Products.CMFCore.interfaces import IDiscussionTool
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFCore.interfaces.Discussions \
         import DiscussionResponse as z2IDiscussionResponse
 from Products.CMFCore.interfaces.portal_discussion \
         import portal_discussion as z2IDiscussionTool
 from Products.CMFCore.utils import getToolByName
+from Products.CMFCore.utils import registerToolInterface
 from Products.CMFCore.utils import UniqueObject
 
 from DiscussionItem import DiscussionItemContainer
@@ -73,7 +77,7 @@
     def overrideDiscussionFor(self, content, allowDiscussion):
         """ Override discussability for the given object or clear the setting.
         """
-        mtool = getToolByName( self, 'portal_membership' )
+        mtool = getUtility(IMembershipTool)
         if not mtool.checkPermission(ModifyPortalContent, content):
             raise AccessControl_Unauthorized
 
@@ -124,3 +128,5 @@
         return content.talkback
 
 InitializeClass( DiscussionTool )
+registerToolInterface('portal_discussion', IDiscussionTool)
+

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/DublinCore.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/DublinCore.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/DublinCore.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -21,10 +21,13 @@
 from Globals import DTMLFile
 from Globals import InitializeClass
 from OFS.PropertyManager import PropertyManager
+
+from zope.component import queryUtility
 from zope.interface import implements
 
 from Products.CMFCore.interfaces import ICatalogableDublinCore
 from Products.CMFCore.interfaces import IDublinCore
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFCore.interfaces import IMutableDublinCore
 from Products.CMFCore.interfaces.DublinCore \
         import CatalogableDublinCore as z2ICatalogableDublinCore
@@ -106,7 +109,7 @@
         """ Add creator to Dublin Core creators.
         """
         if creator is None:
-            mtool = getToolByName(self, 'portal_membership', None)
+            mtool = queryUtility(IMembershipTool)
             creator = mtool and mtool.getAuthenticatedMember().getId()
 
         # call self.listCreators() to make sure self.creators exists

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/MembershipTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/MembershipTool.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/MembershipTool.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -28,6 +28,7 @@
 from Products.CMFCore.utils import _checkPermission
 from Products.CMFCore.utils import _getAuthenticatedUser
 from Products.CMFCore.utils import getToolByName
+from Products.CMFCore.utils import registerToolInterface
 
 from Document import addDocument
 from interfaces import IMembershipTool
@@ -216,3 +217,5 @@
             return None
 
 InitializeClass(MembershipTool)
+registerToolInterface('portal_membership', IMembershipTool)
+

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/RegistrationTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/RegistrationTool.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/RegistrationTool.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -18,11 +18,13 @@
 from AccessControl import ClassSecurityInfo
 from Acquisition import aq_base
 from Globals import InitializeClass
+
+from zope.component import getUtility
 from zope.schema import ValidationError
 
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFCore.RegistrationTool import RegistrationTool as BaseTool
 from Products.CMFCore.utils import _checkPermission
-from Products.CMFCore.utils import getToolByName
 
 from permissions import ManagePortal
 from utils import checkEmailAddress
@@ -126,7 +128,7 @@
 
         o Raise an exception if user ID is not found.
         """
-        membership = getToolByName(self, 'portal_membership')
+        membership = getUtility(IMembershipTool)
         member = membership.getMemberById(forgotten_userid)
 
         if member is None:
@@ -155,7 +157,7 @@
     def registeredNotify( self, new_member_id, password=None ):
         """ Handle mailing the registration / welcome message.
         """
-        membership = getToolByName( self, 'portal_membership' )
+        membership = getUtility(IMembershipTool)
         member = membership.getMemberById( new_member_id )
 
         if member is None:
@@ -195,7 +197,7 @@
           testPropertiesValidity and testPasswordValidity
         """
 
-        mtool = getToolByName(self, 'portal_membership')
+        mtool = getUtility(IMembershipTool)
         member = mtool.getMemberById(member_id)
         member.setMemberProperties(properties)
         member.setSecurityProfile(password,roles,domains)

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml	2006-12-26 17:52:14 UTC (rev 71653)
@@ -3,16 +3,28 @@
  <adapters/>
  <utilities>
   <utility
-     interface="Products.CMFCore.interfaces._tools.IActionsTool"
+     interface="Products.CMFCore.interfaces.IActionsTool"
      object="/portal_actions"/>
   <utility
-     interface="Products.CMFCore.interfaces._tools.ICachingPolicyManager"
+     interface="Products.CMFCore.interfaces.ICachingPolicyManager"
      object="/caching_policy_manager"/>
   <utility
-     interface="Products.CMFCore.interfaces._tools.ICatalogTool"
+     interface="Products.CMFCore.interfaces.ICatalogTool"
      object="/portal_catalog"/>
   <utility
-     interface="Products.CMFCore.interfaces._tools.IContentTypeRegistry"
+     interface="Products.CMFCore.interfaces.IContentTypeRegistry"
      object="/content_type_registry"/>
+  <utility
+     interface="Products.CMFCore.interfaces.ICookieCrumbler"
+     object="/cookie_authentication"/>
+  <utility
+     interface="Products.CMFCore.interfaces.IDiscussionTool"
+     object="/portal_discussion"/>
+  <utility
+     interface="Products.CMFCore.interfaces.IMemberDataTool"
+     object="/portal_memberdata"/>
+  <utility
+     interface="Products.CMFCore.interfaces.IMembershipTool"
+     object="/portal_membership"/>
  </utilities>
 </componentregistry>

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/skins/zpt_generic/getMainGlobals.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/skins/zpt_generic/getMainGlobals.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/skins/zpt_generic/getMainGlobals.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -1,11 +1,17 @@
 ##parameters=
 ##
+
+from Products.CMFCore.utils import getToolByInterfaceName
 from Products.CMFCore.utils import getToolByName
 from Products.CMFDefault.utils import decode
 from Products.CMFDefault.utils import getBrowserCharset
 
-atool = getToolByName(script, 'portal_actions')
-mtool = getToolByName(script, 'portal_membership')
+atool = getToolByInterfaceName( script
+                              , 'Products.CMFCore.interfaces.IActionsTool'
+                              )
+mtool = getToolByInterfaceName( script
+                              , 'Products.CMFCore.interfaces.IMembershipTool'
+                              )
 ptool = getToolByName(script, 'portal_properties')
 utool = getToolByName(script, 'portal_url')
 wtool = getToolByName(script, 'portal_workflow')

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/skins/zpt_generic/news_box.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/skins/zpt_generic/news_box.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/skins/zpt_generic/news_box.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -1,10 +1,12 @@
 ##parameters=
 ##
 from ZTUtils import Batch
-from Products.CMFCore.utils import getToolByName
+from Products.CMFCore.utils import getToolByInterfaceName
 from Products.CMFDefault.utils import decode
 
-ctool = getToolByName(script, 'portal_catalog')
+ctool = getToolByInterfaceName( script
+                              , 'Products.CMFCore.interfaces.ICatalogTool'
+                              )
 
 options = {}
 

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/skins/zpt_generic/password_email.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/skins/zpt_generic/password_email.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/skins/zpt_generic/password_email.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -1,11 +1,14 @@
 ##parameters=member=None, password='secret'
 ##
+from Products.CMFCore.utils import getToolByInterfaceName
 from Products.CMFCore.utils import getToolByName
 from Products.CMFDefault.utils import decode
 from Products.CMFDefault.utils import makeEmail
 from Products.CMFDefault.utils import Message as _
 
-atool = getToolByName(script, 'portal_actions')
+atool = getToolByInterfaceName( script
+                              , 'Products.CMFCore.interfaces.IActionsTool'
+                              )
 ptool = getToolByName(script, 'portal_properties')
 utool = getToolByName(script, 'portal_url')
 portal_url = utool()

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/skins/zpt_generic/registered_email.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/skins/zpt_generic/registered_email.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/skins/zpt_generic/registered_email.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -1,11 +1,14 @@
 ##parameters=member=None, password='secret', email='foo at example.org'
 ##
+from Products.CMFCore.utils import getToolByInterfaceName
 from Products.CMFCore.utils import getToolByName
 from Products.CMFDefault.utils import decode
 from Products.CMFDefault.utils import makeEmail
 from Products.CMFDefault.utils import Message as _
 
-atool = getToolByName(script, 'portal_actions')
+atool = getToolByInterfaceName( script
+                              , 'Products.CMFCore.interfaces.IActionsTool'
+                              )
 ptool = getToolByName(script, 'portal_properties')
 utool = getToolByName(script, 'portal_url')
 portal_url = utool()

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/tests/RegistrationTool.txt
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/tests/RegistrationTool.txt	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/tests/RegistrationTool.txt	2006-12-26 17:52:14 UTC (rev 71653)
@@ -26,9 +26,13 @@
   Now we can set up a RegistrationTool with dummy context::
 
     >>> from Products.CMFDefault.RegistrationTool import RegistrationTool
+    >>> from Products.CMFCore.interfaces import IMembershipTool
+    >>> from zope.component import getSiteManager
     >>> rtool = RegistrationTool()
     >>> rtool.MailHost = MailHost()
     >>> rtool.portal_membership = MembershipTool()
+    >>> sm = getSiteManager()
+    >>> sm.registerUtility(rtool.portal_membership, IMembershipTool)
     >>> rtool.password_email = password_email
     >>> rtool.mail_password_response = mail_password_response
     >>> rtool.registered_email = registered_email
@@ -84,9 +88,12 @@
   Now we can set up password_email and registered_email with dummy context::
 
     >>> from Testing.makerequest import makerequest
+    >>> from Products.CMFCore.interfaces import IActionsTool
     >>> s = makerequest(DummySite())
     >>> s.REQUEST.environ['HTTP_X_FORWARDED_FOR'] = 'NNN.NNN.NNN.NNN'
     >>> s.portal_actions = s.portal_properties = s.portal_url = DummyTool()
+    >>> sm = getSiteManager()
+    >>> sm.registerUtility(s.portal_actions, IActionsTool)
     >>> s.ZopeTime = 'NNNN/NN/NN'
     >>> s.description = 'THE SITE DESCRIPTION.'
     >>> s.default_charset = 'utf-8'

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_DiscussionReply.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_DiscussionReply.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_DiscussionReply.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -20,6 +20,9 @@
 
 from AccessControl.SecurityManagement import newSecurityManager
 
+from zope.component import getSiteManager
+
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFDefault.testing import FunctionalLayer
 
 
@@ -29,6 +32,8 @@
 
     def afterSetUp(self):
         self.portal = self.app.site
+        sm = getSiteManager()
+        sm.registerUtility(self.portal.portal_membership, IMembershipTool)
         # Become a Manager
         self.uf = self.portal.acl_users
         self.uf.userFolderAddUser('manager', '', ['Manager'], [])
@@ -60,6 +65,9 @@
     # else's document.
 
     def afterSetUp(self):
+        self.portal = self.app.site
+        sm = getSiteManager()
+        sm.registerUtility(self.portal.portal_membership, IMembershipTool)
         DiscussionReplyTest.afterSetUp(self)
         self.uf.userFolderAddUser('member', '', ['Member'], [])
         self.site_login('member')

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_DiscussionTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_DiscussionTool.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_DiscussionTool.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -18,6 +18,10 @@
 import unittest
 import Testing
 
+from zope.component import getSiteManager
+
+from Products.CMFCore.interfaces import IDiscussionTool
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFCore.tests.base.dummy import DummyFolder
 from Products.CMFCore.tests.base.dummy import DummySite
 from Products.CMFCore.tests.base.dummy import DummyTool
@@ -32,8 +36,11 @@
 
     def setUp(self):
         self.site = DummySite('site')
+        sm = getSiteManager()
         self.site._setObject( 'portal_discussion', self._makeOne() )
+        sm.registerUtility(self.site.portal_discussion, IDiscussionTool)
         self.site._setObject( 'portal_membership', DummyTool() )
+        sm.registerUtility(self.site.portal_membership, IMembershipTool)
         self.site._setObject( 'portal_types', DummyTool() )
 
     def test_z2interfaces(self):

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_Discussions.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_Discussions.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_Discussions.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -20,9 +20,10 @@
 
 from zope.component import getSiteManager
 
-
 from Products.CMFCore.CatalogTool import CatalogTool
 from Products.CMFCore.interfaces import ICatalogTool
+from Products.CMFCore.interfaces import IDiscussionTool
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFCore.testing import EventZCMLLayer
 from Products.CMFCore.tests.base.dummy import DummyContent
 from Products.CMFCore.tests.base.dummy import DummySite
@@ -32,7 +33,6 @@
 from Products.CMFCore.tests.base.utils import has_path
 from Products.CMFCore.TypesTool import FactoryTypeInformation as FTI
 from Products.CMFCore.TypesTool import TypesTool
-from Products.CMFCore.utils import getToolByName
 from Products.CMFDefault.DiscussionTool import DiscussionTool
 from Products.CMFDefault.exceptions import DiscussionNotAllowed
 
@@ -110,8 +110,11 @@
     def setUp(self):
         SecurityTest.setUp(self)
         self.site = DummySite('site').__of__(self.root)
+        sm = getSiteManager(self.site)
         self.site._setObject( 'portal_discussion', DiscussionTool() )
+        sm.registerUtility(self.site.portal_discussion, IDiscussionTool)
         self.site._setObject( 'portal_membership', DummyTool() )
+        sm.registerUtility(self.site.portal_membership, IMembershipTool)
         self.site._setObject( 'portal_types', TypesTool() )
 
     def _makeDummyContent(self, id, *args, **kw):
@@ -335,7 +338,7 @@
         talkback = dtool.getDiscussionFor(test)
         self.failUnless(hasattr(talkback, 'aq_base'))
         # Acquire a portal tool
-        self.failUnless(getToolByName(talkback, 'portal_discussion'))
+        self.failUnless(getattr(talkback, 'portal_discussion', None))
 
     def test_existingTalkbackIsWrapped(self):
         test = self._makeDummyContent('test')
@@ -345,7 +348,7 @@
         talkback = dtool.getDiscussionFor(test)
         self.failUnless(hasattr(talkback, 'aq_base'))
         # Acquire a portal tool
-        self.failUnless(getToolByName(talkback, 'portal_discussion'))
+        self.failUnless(getattr(talkback, 'portal_discussion', None))
 
 
 def test_suite():

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_DublinCore.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_DublinCore.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_DublinCore.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -22,6 +22,9 @@
 from Acquisition import Implicit
 from DateTime.DateTime import DateTime
 
+from zope.component import getSiteManager
+
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFCore.tests.base.dummy import DummySite
 from Products.CMFCore.tests.base.dummy import DummyUserFolder
 from Products.CMFCore.tests.base.testcase import SecurityTest
@@ -93,8 +96,10 @@
 
     def test_notifyModified(self):
         site = DummySite('site').__of__(self.root)
+        sm = getSiteManager()
         acl_users = site._setObject( 'acl_users', DummyUserFolder() )
         site._setObject( 'portal_membership', MembershipTool() )
+        sm.registerUtility(site.portal_membership, IMembershipTool)
         newSecurityManager(None, acl_users.user_foo)
         item = self._makeDummyContent('item').__of__(site)
         self.assertEqual( item.listCreators(), () )
@@ -107,8 +112,10 @@
 
     def test_creators_methods(self):
         site = DummySite('site').__of__(self.root)
+        sm = getSiteManager()
         acl_users = site._setObject( 'acl_users', DummyUserFolder() )
         site._setObject( 'portal_membership', MembershipTool() )
+        sm.registerUtility(site.portal_membership, IMembershipTool)
         newSecurityManager(None, acl_users.user_foo)
         item = self._makeDummyContent('item').__of__(site)
         self.assertEqual( item.listCreators(), () )
@@ -130,8 +137,10 @@
 
     def test_creators_upgrade(self):
         site = DummySite('site').__of__(self.root)
+        sm = getSiteManager()
         acl_users = site._setObject( 'acl_users', DummyUserFolder() )
         site._setObject( 'portal_membership', MembershipTool() )
+        sm.registerUtility(site.portal_membership, IMembershipTool)
         newSecurityManager(None, acl_users.user_foo)
         item = self._makeDummyContent('item').__of__(site)
         item.manage_fixupOwnershipAfterAdd()

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_Image.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_Image.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_Image.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -29,6 +29,7 @@
 from AccessControl.User import UnrestrictedUser
 
 from Products.CMFCore.interfaces import ICachingPolicyManager
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFCore.testing import ConformsToContent
 from Products.CMFCore.tests.base.dummy import DummyCachingManager
 from Products.CMFCore.tests.base.dummy import DummyCachingManagerWithPolicy
@@ -111,9 +112,11 @@
     layer = FunctionalLayer
 
     def afterSetUp(self):
+        self.site = self.app.site
+        sm = getSiteManager()
+        sm.registerUtility(self.app.site.portal_membership, IMembershipTool)
         newSecurityManager(None, UnrestrictedUser('god', '', ['Manager'], ''))
 
-        self.site = self.app.site
         self.site.invokeFactory('File', id='file')
         self.site.portal_workflow.doActionFor(self.site.file, 'publish')
         self.site.invokeFactory('Image', id='image')

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_Portal.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_Portal.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_Portal.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -25,6 +25,7 @@
 from zope.component import getSiteManager
 
 from Products.CMFCore.interfaces import ICatalogTool
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFDefault.testing import FunctionalLayer
 
 
@@ -37,6 +38,7 @@
 
         sm = getSiteManager()
         sm.registerUtility(self.app.site.portal_catalog, ICatalogTool)
+        sm.registerUtility(self.app.site.portal_membership, IMembershipTool)
 
     def _makeContent( self, site, portal_type, id='document', **kw ):
         newSecurityManager(None, UnrestrictedUser('god', '', ['Manager'], ''))

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_RegistrationTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_RegistrationTool.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_RegistrationTool.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -18,6 +18,9 @@
 import unittest
 from Testing import ZopeTestCase
 
+from zope.component import getSiteManager
+
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFCore.tests.base.testcase import RequestTest
 from Products.CMFDefault.testing import FunctionalLayer
 
@@ -69,6 +72,8 @@
 
         tool = self._makeOne().__of__( self.root )
         self.root.portal_membership = FauxMembershipTool()
+        sm = getSiteManager(self.root)
+        sm.registerUtility(self.root.portal_membership, IMembershipTool)
 
         props = { 'email' : INJECTED_HEADERS
                 , 'username' : 'username'

Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_join.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_join.py	2006-12-26 13:20:58 UTC (rev 71652)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/tests/test_join.py	2006-12-26 17:52:14 UTC (rev 71653)
@@ -18,6 +18,10 @@
 import unittest
 from Testing import ZopeTestCase
 
+from zope.component import getSiteManager
+
+from Products.CMFCore.interfaces import IMemberDataTool
+from Products.CMFCore.interfaces import IMembershipTool
 from Products.CMFDefault.testing import FunctionalLayer
 
 
@@ -25,6 +29,13 @@
 
     layer = FunctionalLayer
 
+    def afterSetUp(self):
+        ZopeTestCase.FunctionalTestCase.afterSetUp(self)
+
+        sm = getSiteManager()
+        sm.registerUtility(self.app.site.portal_memberdata, IMemberDataTool)
+        sm.registerUtility(self.app.site.portal_membership, IMembershipTool)
+
     def test_join( self ):
         site = self.app.site
         member_id = 'test_user'



More information about the CMF-checkins mailing list