[Zope3-checkins] CVS: Zope3/src/zope/app/services - menu.py:1.7
pagefolder.py:1.14
Jim Fulton
jim at zope.com
Sun Sep 21 13:32:54 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv14756/src/zope/app/services
Modified Files:
menu.py pagefolder.py
Log Message:
No-longer use context wrappers.
Changed to use __setitem__ rather than setObject
Merged the previouse decorator into the basic class.
=== Zope3/src/zope/app/services/menu.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/services/menu.py:1.6 Mon Aug 25 10:14:07 2003
+++ Zope3/src/zope/app/services/menu.py Sun Sep 21 13:32:54 2003
@@ -31,8 +31,8 @@
from zope.app.services.servicenames import Utilities, BrowserMenu
from zope.interface import implements
from zope.component.exceptions import ComponentLookupError
-from zope.context import ContextMethod
from zope.interface import providedBy
+from zope.app.container.contained import Contained
class LocalBrowserMenuItem(Persistent):
@@ -95,18 +95,17 @@
return result
- def setObject(self, key, object):
- """See zope.app.interfaces.container.Container"""
+ def addItem(self, object):
self._next += 1
key = str(self._next)
while key in self:
self._next += 1
key = str(self._next)
- super(LocalBrowserMenu, self).setObject(key, object)
+ super(LocalBrowserMenu, self).__setitem__(key, object)
return key
-class LocalBrowserMenuService(BaseBrowserMenuService, Persistent):
+class LocalBrowserMenuService(BaseBrowserMenuService, Persistent, Contained):
"""This implementation strongly depends on the semantics of
GlobalBrowserMenuService."""
@@ -121,7 +120,6 @@
utilities = zapi.getService(self, Utilities)
menus = utilities.getLocalUtilitiesFor(ILocalBrowserMenu)
return map(lambda m: m[1], menus)
- getAllLocalMenus = ContextMethod(getAllLocalMenus)
def getLocalMenu(self, menu_id):
@@ -130,7 +128,6 @@
if menu is None:
raise ComponentLookupError(menu_id)
return menu
- getLocalMenu = ContextMethod(getLocalMenu)
def queryLocalMenu(self, menu_id, default=None):
@@ -141,7 +138,6 @@
if name == menu_id:
return menu
return default
- queryLocalMenu = ContextMethod(queryLocalMenu)
def getInheritedMenu(self, menu_id, canBeLocal=False):
@@ -150,12 +146,11 @@
if menu is None:
raise ComponentLookupError(menu_id)
return menu
- getInheritedMenu = ContextMethod(getInheritedMenu)
def queryInheritedMenu(self, menu_id, canBeLocal=False, default=None):
"""See zope.app.interfaces.services.menu.ILocalBrowserMenuService"""
- if canBeLocal and self.queryLocalMenu(menu_id):
+ if canBeLocal and self.queryLocalMenu(menu_id) is not None:
return self.queryLocalMenu(menu_id)
# Another service (global) should always be available
next = getNextService(self, BrowserMenu)
@@ -165,7 +160,6 @@
return next._registry.get(menu_id, default)
return next.queryInheritedMenu(menu_id, True, default)
- queryInheritedMenu = ContextMethod(queryInheritedMenu)
def getAllMenuItems(self, menu_id, object):
@@ -186,25 +180,21 @@
result += next.getAllMenuItems(menu_id, object)
return tuple(result)
- getAllMenuItems = ContextMethod(getAllMenuItems)
def getMenu(self, menu_id, object, request, max=999999):
"""See zope.app.interfaces.publisher.browser.IBrowserMenuService"""
- return zapi.ContextSuper(LocalBrowserMenuService,
+ return super(LocalBrowserMenuService,
self).getMenu(menu_id, object, request, max)
- getMenu = ContextMethod(getMenu)
def getFirstMenuItem(self, menu_id, object, request):
"""See zope.app.interfaces.publisher.browser.IBrowserMenuService"""
- return zapi.ContextSuper(LocalBrowserMenuService,
+ return super(LocalBrowserMenuService,
self).getFirstMenuItem(menu_id, object, request)
- getFirstMenuItem = ContextMethod(getFirstMenuItem)
def getMenuUsage(self, menu_id):
"""See zope.app.interfaces.publisher.browser.IBrowserMenuService"""
return self.getInheritedMenu(menu_id, True).usage
- getMenuUsage = ContextMethod(getMenuUsage)
=== Zope3/src/zope/app/services/pagefolder.py 1.13 => 1.14 ===
--- Zope3/src/zope/app/services/pagefolder.py:1.13 Mon Jul 7 13:15:03 2003
+++ Zope3/src/zope/app/services/pagefolder.py Sun Sep 21 13:32:54 2003
@@ -21,11 +21,9 @@
__metaclass__ = type
from zope.app.container.btree import BTreeContainer
-from zope.app.container.zopecontainer import ZopeContainerDecorator
from zope.app.interfaces.services.view import IZPTTemplate
from zope.publisher.interfaces.browser import IBrowserPresentation
from zope.app.traversing import getPath
-from zope.app.context import getItem
from zope.app.interfaces.services.registration import ActiveStatus
from zope.app.services.registration import RegistrationManagerContainer
from zope.proxy import removeAllProxies
@@ -59,65 +57,17 @@
########################################################
- def setObject(self, name, object):
+ def __setitem__(self, name, object):
if (IRegistrationManager.isImplementedBy(object) or
IZPTTemplate.isImplementedBy(object)):
- return super(PageFolder, self).setObject(name, object)
+ super(PageFolder, self).__setitem__(name, object)
else:
raise TypeError("Can only add templates", object)
-_attrNames = (
- 'factoryName',
- 'forInterface',
- 'layer',
- 'permission',
- )
-
-class PageFolderAdapter(ObjectEntryAdapter):
- """ObjectFile adapter for PageFolder objects."""
-
- implements(IObjectDirectory)
-
- def contents(self):
- return self.context.items()
-
- def extra(self):
- return AttrMapping(self.context, _attrNames)
-
-
-class PageFolderFactory:
-
- implements(IDirectoryFactory)
-
- def __init__(self, context):
- self.context = context
-
- def __call__(self, name):
- return PageFolder()
-
-class PageFolderContextDecorator(ZopeContainerDecorator):
-
- # The logic for handling registrations is provided here.
- #
- # There are 2 reasons for this:
- #
- # 1. It may be clearer to let decorators, which are context
- # wrappers. handle context-sensitive logic.
- #
- # 2. There is a limitation that decorators can't delegate
- # to context-methods of the objects they decorate. That means
- # we can't make PageFolder's setObject method context aware,
- # because PageFolders, will get decorated with container
- # decorators that define setObject (to generate necessary
- # events).
-
- def setObject(self, name, object):
- name = super(PageFolderContextDecorator, self).setObject(name, object)
-
# If a template is added, we need to configure it too.
if IZPTTemplate.isImplementedBy(object):
- template = getItem(self, name)
+ template = self[name]
template = getPath(template)
registration = PageRegistration(
forInterface=self.forInterface,
@@ -129,12 +79,10 @@
)
registrations = self.getRegistrationManager()
- id = registrations.setObject('', registration)
- registration = getItem(registrations, id)
+ id = registrations.addRegistration(registration)
+ registration = registrations[id]
registration.status = ActiveStatus
- return name
-
def applyDefaults(self):
"""Apply the default configuration to the already-registered pages.
"""
@@ -159,6 +107,36 @@
# Now restore the registration status
registration.status = status
+
+
+_attrNames = (
+ 'factoryName',
+ 'forInterface',
+ 'layer',
+ 'permission',
+ )
+
+class PageFolderAdapter(ObjectEntryAdapter):
+ """ObjectFile adapter for PageFolder objects."""
+
+ implements(IObjectDirectory)
+
+ def contents(self):
+ return self.context.items()
+
+ def extra(self):
+ return AttrMapping(self.context, _attrNames)
+
+
+class PageFolderFactory:
+
+ implements(IDirectoryFactory)
+
+ def __init__(self, context):
+ self.context = context
+
+ def __call__(self, name):
+ return PageFolder()
# XXX Backward compatibility. This is needed to support old pickles.
More information about the Zope3-Checkins
mailing list