[Zope3-checkins] CVS: Zope3/src/zope/app/services -
adapter.py:1.21.18.1 auth.py:1.19.24.1 cache.py:1.18.6.1
configure.zcml:1.56.6.1 connection.py:1.20.4.1
error.py:1.2.6.1 event.py:1.34.12.1 folder.py:1.13.6.1
hub.py:1.20.8.1 interface.py:1.16.6.1 menu.py:1.6.4.1
module.py:1.14.6.1 pagefolder.py:1.13.18.1
pagefolder.zcml:1.2.4.1 principalannotation.py:1.9.24.1
registration.py:1.14.4.1 role.py:1.6.24.1
service.py:1.29.18.1 servicecontainer.py:1.5.2.1
session.py:1.10.24.1 utility.py:1.16.6.1 view.py:1.34.6.1
zpt.py:1.13.24.1
Jim Fulton
jim at zope.com
Mon Sep 8 15:22:19 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv20092/src/zope/app/services
Modified Files:
Tag: parentgeddon-branch
adapter.py auth.py cache.py configure.zcml connection.py
error.py event.py folder.py hub.py interface.py menu.py
module.py pagefolder.py pagefolder.zcml principalannotation.py
registration.py role.py service.py servicecontainer.py
session.py utility.py view.py zpt.py
Log Message:
Checking in work in progress on parentgeddon-branch so Fred can help
me to get the tests passing. Specific log entries will be provided
when we merge this into the head.
=== Zope3/src/zope/app/services/adapter.py 1.21 => 1.21.18.1 ===
--- Zope3/src/zope/app/services/adapter.py:1.21 Mon Jun 30 12:24:38 2003
+++ Zope3/src/zope/app/services/adapter.py Mon Sep 8 14:21:47 2003
@@ -29,11 +29,10 @@
from zope.app.interfaces.services.registration import IRegistry
from zope.app.services.registration import RegistrationStack
from zope.app.services.registration import SimpleRegistration
-from zope.app.context import ContextWrapper
from zope.app.component.nextservice import getNextService
from zope.app.interfaces.services.service import ISimpleService
-
from zope.app.interfaces.services.adapter import IAdapterRegistration
+from zope.app.container.contained import Contained
class PersistentAdapterRegistry(Persistent, AdapterRegistry):
@@ -41,7 +40,7 @@
AdapterRegistry.__init__(self, PersistentDict())
-class AdapterService(Persistent):
+class AdapterService(Persistent, Contained):
implements(IAdapterService, IRegistry, ISimpleService)
@@ -56,8 +55,6 @@
registration.adapterName,
default)
- queryRegistrationsFor = zapi.ContextMethod(queryRegistrationsFor)
-
def queryRegistrations(self,
forInterface, providedInterface, adapterName,
default=None):
@@ -70,9 +67,7 @@
if registry is None:
return default
- return ContextWrapper(registry, self)
-
- queryRegistrations = zapi.ContextMethod(queryRegistrations)
+ return registry
def createRegistrationsFor(self, registration):
"See IRegistry"
@@ -81,8 +76,6 @@
registration.forInterface, registration.providedInterface,
registration.adapterName)
- createRegistrationsFor = zapi.ContextMethod(createRegistrationsFor)
-
def createRegistrations(self, forInterface, providedInterface, name):
adapters = self._byName.get(name)
@@ -92,12 +85,10 @@
registry = adapters.getRegistered(forInterface, providedInterface)
if registry is None:
- registry = RegistrationStack()
+ registry = RegistrationStack(self)
adapters.register(forInterface, providedInterface, registry)
- return ContextWrapper(registry, self)
-
- createRegistrations = zapi.ContextMethod(createRegistrations)
+ return registry
def getAdapter(self, object, interface, name=''):
"See IAdapterService"
@@ -106,8 +97,6 @@
raise ComponentLookupError(object, interface)
return adapter
- getAdapter = zapi.ContextMethod(getAdapter)
-
def getNamedAdapter(self, object, interface, name):
"See IAdapterService"
adapter = self.queryNamedAdapter(object, interface, name)
@@ -115,8 +104,6 @@
raise ComponentLookupError(object, interface)
return adapter
- getNamedAdapter = zapi.ContextMethod(getNamedAdapter)
-
def queryAdapter(self, object, interface, default=None, name=''):
"""see IAdapterService interface"""
if name:
@@ -150,20 +137,16 @@
return self.queryNamedAdapter(object, interface, name, default)
- queryAdapter = zapi.ContextMethod(queryAdapter)
-
def queryNamedAdapter(self, object, interface, name, default=None):
adapters = self._byName.get(name)
if adapters:
registry = adapters.getForObject(
object, interface,
- filter = lambda registry:
- ContextWrapper(registry, self).active(),
+ filter = lambda registry: registry.active(),
)
if registry is not None:
- registry = ContextWrapper(registry, self)
adapter = registry.active().getAdapter(object)
return adapter
@@ -171,8 +154,6 @@
return adapters.queryNamedAdapter(object, interface, name, default)
- queryNamedAdapter = zapi.ContextMethod(queryNamedAdapter)
-
# XXX need to add name support
def getRegisteredMatching(self,
for_interfaces=None,
@@ -210,11 +191,9 @@
self.factoryName = factoryName
def getAdapter(self, object):
- folder = zapi.getWrapperContainer(zapi.getWrapperContainer(self))
+ folder = self.__parent__.__parent__
factory = folder.resolve(self.factoryName)
return factory(object)
-
- getAdapter = zapi.ContextMethod(getAdapter)
# XXX Pickle backward compatability
AdapterConfiguration = AdapterRegistration
=== Zope3/src/zope/app/services/auth.py 1.19 => 1.19.24.1 ===
--- Zope3/src/zope/app/services/auth.py:1.19 Sat Jun 7 01:31:58 2003
+++ Zope3/src/zope/app/services/auth.py Mon Sep 8 14:21:47 2003
@@ -33,9 +33,9 @@
from zope.proxy import removeAllProxies
from zope.app.attributeannotations import AttributeAnnotations
from zope.app.component.nextservice import getNextService
-from zope.context import ContextMethod
from zope.app.interfaces.services.service import ISimpleService
from zope.interface import implements
+from zope.app.container.contained import Contained
class DuplicateLogin(Exception):
@@ -45,7 +45,7 @@
pass
-class AuthenticationService(Persistent):
+class AuthenticationService(Persistent, Contained):
implements(IAuthenticationService, IContainer, ISimpleService)
@@ -78,8 +78,6 @@
next = getNextService(self, Authentication)
return next.authenticate(request)
- authenticate = ContextMethod(authenticate)
-
def unauthenticatedPrincipal(self):
'See IAuthenticationService'
return None
@@ -98,8 +96,6 @@
except KeyError:
next = getNextService(self, Authentication)
return next.getPrincipal(id)
-
- getPrincipal = ContextMethod(getPrincipal)
def getPrincipals(self, name):
'See IAuthenticationService'
=== Zope3/src/zope/app/services/cache.py 1.18 => 1.18.6.1 ===
--- Zope3/src/zope/app/services/cache.py:1.18 Tue Aug 19 19:11:05 2003
+++ Zope3/src/zope/app/services/cache.py Mon Sep 8 14:21:47 2003
@@ -24,8 +24,9 @@
from zope.app.services.event import ServiceSubscriberEventChannel
from zope.app.services.servicenames import Utilities
from zope.interface import implements
+from zope.app.container.contained import Contained
-class CachingService(ServiceSubscriberEventChannel, Persistent):
+class CachingService(ServiceSubscriberEventChannel, Persistent, Contained):
implements(ILocalCachingService, ISimpleService)
@@ -38,17 +39,17 @@
'See ICachingService'
utilities = zapi.getService(self, Utilities)
return utilities.getUtility(ICache, name)
- getCache = zapi.ContextMethod(getCache)
+
def queryCache(self, name, default=None):
'See ICachingService'
utilities = zapi.getService(self, Utilities)
return utilities.queryUtility(ICache, default, name)
- queryCache = zapi.ContextMethod(queryCache)
+
def getAvailableCaches(self):
'See ICachingService'
utilities = zapi.getService(self, Utilities)
caches = utilities.getUtilitiesFor(ICache)
return map(lambda c: c[0], caches)
- getAvailableCaches = zapi.ContextMethod(getAvailableCaches)
+
=== Zope3/src/zope/app/services/configure.zcml 1.56 => 1.56.6.1 ===
--- Zope3/src/zope/app/services/configure.zcml:1.56 Tue Aug 19 13:34:24 2003
+++ Zope3/src/zope/app/services/configure.zcml Mon Sep 8 14:21:47 2003
@@ -193,17 +193,6 @@
/>
</content>
-<!-- Caching Service -->
-
- <content class="zope.app.services.cache.CachingService">
- <factory
- id="zope.services.CachingService"
- permission="zope.ManageServices" />
- <require
- permission="zope.View"
- interface="zope.app.interfaces.cache.ICachingService" />
- </content>
-
<!-- Service Manager -->
<content class="zope.app.services.service.ServiceManager">
=== Zope3/src/zope/app/services/connection.py 1.20 => 1.20.4.1 ===
--- Zope3/src/zope/app/services/connection.py:1.20 Thu Aug 21 08:01:21 2003
+++ Zope3/src/zope/app/services/connection.py Mon Sep 8 14:21:47 2003
@@ -22,8 +22,9 @@
from zope.app.interfaces.services.service import ISimpleService
from zope.app.services.servicenames import Utilities
from zope.interface import implements
+from zope.app.container.contained import Contained
-class ConnectionService(Persistent):
+class ConnectionService(Persistent, Contained):
"""This is a local relational database connection service."""
implements(ILocalConnectionService, ISimpleService)
@@ -33,7 +34,6 @@
utilities = zapi.getService(self, Utilities)
dbadapter = utilities.getUtility(IZopeDatabaseAdapter, name)
return dbadapter()
- getConnection = zapi.ContextMethod(getConnection)
def queryConnection(self, name, default=None):
'See IConnectionService'
@@ -43,11 +43,9 @@
return dbadapter()
else:
return default
- queryConnection = zapi.ContextMethod(queryConnection)
def getAvailableConnections(self):
'See IConnectionService'
utilities = zapi.getService(self, Utilities)
connections = utilities.getUtilitiesFor(IZopeDatabaseAdapter)
return map(lambda c: c[0], connections)
- getAvailableConnections = zapi.ContextMethod(getAvailableConnections)
=== Zope3/src/zope/app/services/error.py 1.2 => 1.2.6.1 ===
--- Zope3/src/zope/app/services/error.py:1.2 Tue Aug 12 17:26:26 2003
+++ Zope3/src/zope/app/services/error.py Mon Sep 8 14:21:47 2003
@@ -25,11 +25,11 @@
from zope.app.interfaces.services.error import IErrorReportingService
from zope.app.interfaces.services.error import ILocalErrorReportingService
from zope.app.interfaces.services.service import ISimpleService
-from zope.context import ContextMethod
from zope.exceptions.exceptionformatter import format_exception
from zope.interface import implements
import logging
import time
+from zope.app.container.contained import Contained
#Restrict the rate at which errors are sent to the Event Log
_rate_restrict_pool = {}
@@ -48,7 +48,7 @@
cleanup_lock = allocate_lock()
-class ErrorReportingService(Persistent):
+class ErrorReportingService(Persistent, Contained):
"""Error Reporting Service
"""
implements(IErrorReportingService,
@@ -165,7 +165,6 @@
self._do_copy_to_zlog(now, strtype, str(url), info)
finally:
info = None
- raising = ContextMethod(raising)
def _do_copy_to_zlog(self, now, strtype, url, info):
# XXX info is unused; logging.exception() will call sys.exc_info()
@@ -187,7 +186,6 @@
'copy_to_zlog': self.copy_to_zlog,
'ignored_exceptions': self._ignored_exceptions,
}
- getProperties = ContextMethod(getProperties)
def setProperties(self, keep_entries, copy_to_zlog=0,
ignored_exceptions=()):
@@ -199,7 +197,7 @@
self._ignored_exceptions = tuple(
filter(None, map(str, ignored_exceptions))
)
- setProperties = ContextMethod(setProperties)
+
def getLogEntries(self):
"""Returns the entries in the log, most recent first.
@@ -208,7 +206,6 @@
res = [entry.copy() for entry in self._getLog()]
res.reverse()
return res
- getLogEntries = ContextMethod(getLogEntries)
def getLogEntryById(self, id):
"""Returns the specified log entry.
@@ -218,7 +215,6 @@
if entry['id'] == id:
return entry.copy()
return None
- getLogEntryById = ContextMethod(getLogEntryById)
class RootErrorReportingService(ErrorReportingService):
rootId = 'root'
=== Zope3/src/zope/app/services/event.py 1.34 => 1.34.12.1 ===
--- Zope3/src/zope/app/services/event.py:1.34 Mon Jul 14 07:07:22 2003
+++ Zope3/src/zope/app/services/event.py Mon Sep 8 14:21:47 2003
@@ -39,6 +39,7 @@
from zope.app.event.subs import Subscribable, SubscriptionTracker
from zope.security.proxy import trustedRemoveSecurityProxy
+from zope.app.container.contained import Contained
import logging
@@ -142,7 +143,6 @@
def notify(wrapped_self, event):
clean_self = removeAllProxies(wrapped_self)
clean_self._notify(wrapped_self, event)
- notify = zapi.ContextMethod(notify)
class ServiceSubscriberEventChannel(SubscriptionTracker, EventChannel):
@@ -170,13 +170,12 @@
_subscribeToServiceInterface = IEvent
_subscribeToServiceFilter = None
- def subscribe(wrapped_self, reference, event_type=IEvent, filter=None):
- if getattr(wrapped_self, "_v_ssecunbinding", None) is not None:
+ def subscribe(self, reference, event_type=IEvent, filter=None):
+ if getattr(self, "_v_ssecunbinding", None) is not None:
raise Exception(
'Cannot subscribe to a subscriber that is unbinding.')
- return zapi.ContextSuper(ServiceSubscriberEventChannel, wrapped_self
- ).subscribe(reference, event_type, filter)
- subscribe = zapi.ContextMethod(subscribe)
+ return super(ServiceSubscriberEventChannel, self
+ ).subscribe(reference, event_type, filter)
def bound(wrapped_self, name):
"See IBindingAware"
@@ -205,7 +204,6 @@
clean_self._subscribeToServiceInterface,
clean_self._subscribeToServiceFilter
)
- bound = zapi.ContextMethod(bound)
def unbound(wrapped_self, name):
"See IBindingAware"
@@ -253,7 +251,6 @@
assert len(paths) == len(hubIds) == len(clean_self._registry) == 0
clean_self._serviceName = None
- unbound = zapi.ContextMethod(unbound)
class ServiceSubscribable(Subscribable):
@@ -273,75 +270,69 @@
# requires __init__ from zope.app.event.subs.Subscribable
- def unsubscribe(wrapped_self, reference, event_type, filter=None):
+ def unsubscribe(self, reference, event_type, filter=None):
# The point here is that if we can't unsubscribe here, we should
# allow the next event service to unsubscribe.
try:
- zapi.ContextSuper(ServiceSubscribable, wrapped_self).unsubscribe(
- reference, event_type, filter)
+ super(ServiceSubscribable, self
+ ).unsubscribe(reference, event_type, filter)
except NotFoundError:
- next_service = queryNextService(wrapped_self,
- wrapped_self._serviceName)
+ next_service = queryNextService(self,
+ self._serviceName)
if next_service is not None:
next_service.unsubscribe(reference, event_type, filter)
else:
raise
- unsubscribe = zapi.ContextMethod(unsubscribe)
- def unsubscribeAll(wrapped_self, reference, event_type=IEvent,
+ def unsubscribeAll(self, reference, event_type=IEvent,
local_only=False):
# unsubscribe all from here, and from the next service
# n is the number of subscriptions removed
- n = zapi.ContextSuper(ServiceSubscribable, wrapped_self).unsubscribeAll(
- reference, event_type)
+ n = super(ServiceSubscribable, self
+ ).unsubscribeAll(reference, event_type)
if not local_only:
- next_service = queryNextService(wrapped_self,
- wrapped_self._serviceName)
+ next_service = queryNextService(self, self._serviceName)
if next_service is not None:
n += next_service.unsubscribeAll(reference, event_type)
return n
- unsubscribeAll = zapi.ContextMethod(unsubscribeAll)
- def resubscribeByHubId(wrapped_self, reference):
- n = zapi.ContextSuper(ServiceSubscribable, wrapped_self
- ).resubscribeByHubId(reference)
- next_service = queryNextService(wrapped_self,
- wrapped_self._serviceName)
+ def resubscribeByHubId(self, reference):
+ n = super(ServiceSubscribable, self
+ ).resubscribeByHubId(reference)
+ next_service = queryNextService(self, self._serviceName)
if next_service is not None:
n += next_service.resubscribeByHubId(reference)
return n
- def resubscribeByPath(wrapped_self, reference):
- n = zapi.ContextSuper(ServiceSubscribable, wrapped_self
- ).resubscribeByPath(reference)
- next_service = queryNextService(wrapped_self,
- wrapped_self._serviceName)
+ def resubscribeByPath(self, reference):
+ n = super(ServiceSubscribable, self
+ ).resubscribeByPath(reference)
+ next_service = queryNextService(self, self._serviceName)
if next_service is not None:
n += next_service.resubscribeByPath(reference)
return n
- def iterSubscriptions(wrapped_self, reference=None, event_type=IEvent,
+ def iterSubscriptions(self, reference=None, event_type=IEvent,
local_only=False):
'See ISubscriptionService'
- subs = zapi.ContextSuper(ServiceSubscribable, wrapped_self
- ).iterSubscriptions(reference, event_type)
+ subs = super(ServiceSubscribable, self
+ ).iterSubscriptions(reference, event_type)
for subscription in subs:
yield subscription
if not local_only:
- next_service = queryNextService(wrapped_self,
- wrapped_self._serviceName)
+ next_service = queryNextService(self, self._serviceName)
if next_service is not None:
for subscription in next_service.iterSubscriptions(
reference, event_type):
yield subscription
- iterSubscriptions = zapi.ContextMethod(iterSubscriptions)
from zope.app.interfaces.services.service import ISimpleService
-class EventService(ServiceSubscriberEventChannel, ServiceSubscribable):
+class EventService(ServiceSubscriberEventChannel, ServiceSubscribable,
+ Contained):
implements(IEventService, ISubscriptionService, ISimpleService)
@@ -371,7 +362,6 @@
getNextService(wrapped_self, EventPublication).publish(event)
finally:
publishedEvents.remove(event)
- publish = zapi.ContextMethod(publish)
def notify(wrapped_self, event):
"see ISubscriber"
@@ -379,7 +369,6 @@
publishedEvents = getattr(clean_self, "_v_publishedEvents", [])
if event not in publishedEvents:
clean_self._notify(wrapped_self, event)
- notify = zapi.ContextMethod(notify)
def bound(wrapped_self, name):
"See IBindingAware"
@@ -396,32 +385,30 @@
pass
else:
es.subscribe(wrapped_self)
- bound = zapi.ContextMethod(bound)
- def unbound(wrapped_self, name):
+ def unbound(self, name):
"See IBindingAware"
# An event service is bound as EventSubscription and EventPublication.
# We only want to unsubscribe from the next event service when
# we're unbound as EventSubscription
if name == EventSubscription:
- clean_self = removeAllProxies(wrapped_self)
+ clean_self = removeAllProxies(self)
# This flag is used by the unsubscribedFrom method (below) to
# determine that it doesn't need to further unsubscribe beyond
# what we're already doing.
clean_self._v_unbinding = True
try:
- zapi.ContextSuper(EventService, wrapped_self).unbound(name)
+ super(EventService, self).unbound(name)
finally:
# unset flag
del clean_self._v_unbinding
- unbound = zapi.ContextMethod(unbound)
- def unsubscribedFrom(wrapped_self, subscribable, event_type, filter):
+ def unsubscribedFrom(self, subscribable, event_type, filter):
"See ISubscribingAware"
- zapi.ContextSuper(EventService, wrapped_self).unsubscribedFrom(
- subscribable, event_type, filter)
- clean_self = removeAllProxies(wrapped_self)
+ super(EventService, self
+ ).unsubscribedFrom(subscribable, event_type, filter)
+ clean_self = removeAllProxies(self)
if getattr(clean_self, "_v_unbinding", None) is None:
# we presumably have been unsubscribed from a higher-level
# event service because that event service is unbinding
@@ -432,7 +419,7 @@
if ISubscriptionService.isImplementedBy(
removeAllProxies(clean_subscribable)):
try:
- context = zapi.getService(wrapped_self, EventSubscription)
+ context = zapi.getService(self, EventSubscription)
# we do this instead of getNextService because the order
# of unbinding and notification of unbinding is not
# guaranteed
@@ -442,6 +429,5 @@
except ComponentLookupError:
pass
else:
- context.subscribe(wrapped_self)
- unsubscribedFrom = zapi.ContextMethod(unsubscribedFrom)
+ context.subscribe(self)
=== Zope3/src/zope/app/services/folder.py 1.13 => 1.13.6.1 ===
--- Zope3/src/zope/app/services/folder.py:1.13 Tue Aug 12 18:00:18 2003
+++ Zope3/src/zope/app/services/folder.py Mon Sep 8 14:21:47 2003
@@ -27,8 +27,6 @@
from zope.app.interfaces.file import IDirectoryFactory
from zope.app.services.registration import RegistrationManagerContainer
from zope.app.traversing import getPath
-from zope.app.context import ContextWrapper
-from zope.context import ContextMethod
from zope.interface import implements
class SiteManagementFolder(RegistrationManagerContainer, BTreeContainer):
@@ -38,24 +36,26 @@
class SiteManagementFolders(BTreeContainer):
implements(ISiteManagementFolders)
- def __init__(self):
+ def __init__(self, container):
+ self.__parent__ = container
super(SiteManagementFolders, self).__init__()
- self.setObject('default', SiteManagementFolder())
+ f = SiteManagementFolder()
+ f.__name__ = 'default'
+ self.setObject('default', f)
def queryComponent(self, type=None, filter=None, all=0):
local = []
path = getPath(self)
for pkg_name in self:
- package = ContextWrapper(self[pkg_name], self, name=pkg_name)
+ package = self[pkg_name]
for name in package:
component = package[name]
if type is not None and not type.isImplementedBy(component):
continue
if filter is not None and not filter(component):
continue
- wrapper = ContextWrapper(component, package, name=name)
local.append({'path': "%s/%s/%s" % (path, pkg_name, name),
- 'component': wrapper,
+ 'component': component,
})
if all:
@@ -67,12 +67,18 @@
return local
- queryComponent = ContextMethod(queryComponent)
-
def setObject(self, name, obj):
if not (ISiteManagementFolder.isImplementedBy(obj)
or IBundle.isImplementedBy(obj)):
raise TypeError("Can only add packages")
+
+ # Disallow the name "Packages"
+ if name == "Packages":
+ raise ValueError("Packages is not a valid package name")
+
+ # We want out items to be virtually contained in our container
+ obj.__parent__ = self.__parent__
+
return super(SiteManagementFolders, self).setObject(name, obj)
class SMFolderFactory(object):
=== Zope3/src/zope/app/services/hub.py 1.20 => 1.20.8.1 ===
--- Zope3/src/zope/app/services/hub.py:1.20 Thu Aug 7 11:32:41 2003
+++ Zope3/src/zope/app/services/hub.py Mon Sep 8 14:21:47 2003
@@ -29,7 +29,6 @@
from zope.component import getAdapter, getService
from zope.exceptions import NotFoundError
-from zope.context import ContextMethod
from zope.proxy import removeAllProxies
from zope.app.services.servicenames import EventSubscription
@@ -58,6 +57,7 @@
from zope.app.interfaces.services.hub import ObjectHubError
from zope.app.interfaces.services.hub import ISubscriptionControl
from persistence import Persistent
+from zope.app.container.contained import Contained
class HubEvent:
"""Convenient mix-in for HubEvents"""
@@ -180,7 +180,7 @@
# Return a canonical path, with a slash appended
return canonicalPath(path) + u'/'
-class ObjectHub(ServiceSubscriberEventChannel):
+class ObjectHub(ServiceSubscriberEventChannel, Contained):
# this implementation makes the decision to not interact with any
# object hubs above it: it is a world unto itself, as far as it is
@@ -245,7 +245,6 @@
event = ObjectRemovedHubEvent(
event.object, hubid, pathslash[:-1], event.object)
clean_self._notify(wrapped_self, event)
- notify = ContextMethod(notify)
def getHubId(self, path_or_object):
'''See interface ILocalObjectHub'''
@@ -274,7 +273,6 @@
adapter = getAdapter(wrapped_self, ITraverser)
wrapped_self._verifyPath(path, adapter)
return adapter.traverse(path)
- getObject = ContextMethod(getObject)
def register(wrapped_self, path_or_object):
'''See interface ILocalObjectHub'''
@@ -303,7 +301,6 @@
wrapped_self, hubid, pathslash[:-1], obj)
clean_self._notify(wrapped_self, event)
return hubid
- register = ContextMethod(register)
def unregister(wrapped_self, path_or_object_or_hubid):
'''See interface ILocalObjectHub'''
@@ -331,7 +328,6 @@
event = ObjectUnregisteredHubEvent(
wrapped_self, hubid, pathslash[:-1])
clean_self._notify(wrapped_self, event)
- unregister = ContextMethod(unregister)
def numRegistrations(self):
"""See interface IObjectHub"""
@@ -364,7 +360,6 @@
traverser = getAdapter(wrapped_self, ITraverser)
for path, hubId in wrapped_self.iterRegistrations():
yield (path, hubId, wrapped_self._safeTraverse(path, traverser))
- iterObjectRegistrations = ContextMethod(iterObjectRegistrations)
############################################################
@@ -387,7 +382,6 @@
except NotFoundError, e:
wrapped_self.unregister(path)
raise e
- _verifyPath = ContextMethod(_verifyPath)
def _safeTraverse(self, path, traverser):
@@ -406,7 +400,6 @@
for path in missing:
wrapped_self.unregister(path)
return len(missing)
- unregisterMissingObjects = ContextMethod(unregisterMissingObjects)
"""A simple-minded registration object.
@@ -427,7 +420,7 @@
"""
-class Registration(Persistent):
+class Registration(Persistent, Contained):
implements(ISubscriptionControl, ISubscriber)
@@ -442,7 +435,6 @@
if event.__class__ is ObjectAddedEvent:
hub = getService(wrapped_self, HubIds)
wrapped_self._registerObject(event.location, hub)
- notify = ContextMethod(notify)
currentlySubscribed = False # Default subscription state
@@ -454,7 +446,6 @@
events = getService(wrapped_self, EventSubscription)
events.subscribe(wrapped_self, IObjectAddedEvent)
wrapped_self.currentlySubscribed = True
- subscribe = ContextMethod(subscribe)
def unsubscribe(wrapped_self):
if not wrapped_self.currentlySubscribed:
@@ -462,7 +453,6 @@
events = getService(wrapped_self, EventSubscription)
events.unsubscribe(wrapped_self, IObjectAddedEvent)
wrapped_self.currentlySubscribed = False
- unsubscribe = ContextMethod(unsubscribe)
def isSubscribed(self):
return self.currentlySubscribed
@@ -471,7 +461,6 @@
object = findContentObject(wrapped_self)
hub = getService(wrapped_self, HubIds)
wrapped_self._registerTree(object, hub)
- registerExisting = ContextMethod(registerExisting)
def _registerTree(wrapped_self, object, hub):
wrapped_self._registerObject(object, hub)
@@ -484,7 +473,6 @@
for name in names:
sub_object = traverseName(object, name, traversable=traversable)
wrapped_self._registerTree(sub_object, hub)
- _registerTree = ContextMethod(_registerTree)
def _registerObject(wrapped_self, location, hub):
# XXX Policy decision: register absolutely everything
@@ -493,7 +481,6 @@
except ObjectHubError:
# Already registered
pass
- _registerObject = ContextMethod(_registerObject)
def findContentObject(context):
# We want to find the (content) Folder in whose service manager we
=== Zope3/src/zope/app/services/interface.py 1.16 => 1.16.6.1 ===
--- Zope3/src/zope/app/services/interface.py:1.16 Sun Aug 17 02:08:11 2003
+++ Zope3/src/zope/app/services/interface.py Mon Sep 8 14:21:47 2003
@@ -32,6 +32,9 @@
from zope.app.services.servicenames import Interfaces, Utilities
from zope.component import ComponentLookupError
from zope.interface import implements
+from zope.app.container.contained import Contained
+from zope.interface.interfaces import IInterface
+from zope.app.interfaces.services.registration import IRegistrationStack
class PersistentInterfaceClass(Persistent, InterfaceClass):
pass
@@ -54,14 +57,11 @@
)
-class LocalInterfaceService(object):
+class LocalInterfaceService(Contained):
"""A local interface service."""
implements(IInterfaceService,
ISimpleService)
-
- # All the methods defined here are context methods
- zapi.ContextAwareDescriptors()
def getInterface(self, id):
# Return the interface registered for the given id
=== Zope3/src/zope/app/services/menu.py 1.6 => 1.6.4.1 ===
--- Zope3/src/zope/app/services/menu.py:1.6 Mon Aug 25 10:14:07 2003
+++ Zope3/src/zope/app/services/menu.py Mon Sep 8 14:21:47 2003
@@ -31,11 +31,11 @@
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):
+class LocalBrowserMenuItem(Persistent, Contained):
"""A persistent browser menu item."""
implements(IBrowserMenuItem)
@@ -121,7 +121,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 +129,6 @@
if menu is None:
raise ComponentLookupError(menu_id)
return menu
- getLocalMenu = ContextMethod(getLocalMenu)
def queryLocalMenu(self, menu_id, default=None):
@@ -141,7 +139,6 @@
if name == menu_id:
return menu
return default
- queryLocalMenu = ContextMethod(queryLocalMenu)
def getInheritedMenu(self, menu_id, canBeLocal=False):
@@ -150,7 +147,6 @@
if menu is None:
raise ComponentLookupError(menu_id)
return menu
- getInheritedMenu = ContextMethod(getInheritedMenu)
def queryInheritedMenu(self, menu_id, canBeLocal=False, default=None):
@@ -165,7 +161,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 +181,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/module.py 1.14 => 1.14.6.1 ===
--- Zope3/src/zope/app/services/module.py:1.14 Sun Aug 17 02:08:11 2003
+++ Zope3/src/zope/app/services/module.py Mon Sep 8 14:21:47 2003
@@ -28,13 +28,12 @@
from zope.app.interfaces.services.module import IModuleManager
from zope.interface import implements
from zope.security.proxy import trustedRemoveSecurityProxy
+from zope.app.container.contained import Contained
-class Manager(Persistent):
+class Manager(Persistent, Contained):
implements(IModuleManager, IAttributeAnnotatable)
- zapi.ContextAwareDescriptors()
-
def __init__(self, name, source):
self.name = name
self._source = None
@@ -58,7 +57,7 @@
mod = self._module = PersistentModule(self.name)
- folder = zapi.getWrapperContainer(self)
+ folder = self.__parent__
# XXX
# We are currently only supporting trusted code.
@@ -114,7 +113,7 @@
assert name.endswith(".py")
name = name[:-3]
m = Manager(name, data)
- m = zapi.ContextWrapper(m, self.context)
+ m.__parent__ = self.context
m.execute()
return m
=== Zope3/src/zope/app/services/pagefolder.py 1.13 => 1.13.18.1 ===
--- Zope3/src/zope/app/services/pagefolder.py:1.13 Mon Jul 7 13:15:03 2003
+++ Zope3/src/zope/app/services/pagefolder.py Mon Sep 8 14:21:47 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
@@ -67,57 +65,9 @@
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,
@@ -130,7 +80,7 @@
registrations = self.getRegistrationManager()
id = registrations.setObject('', registration)
- registration = getItem(registrations, id)
+ registration = registrations[id]
registration.status = ActiveStatus
return name
@@ -159,6 +109,40 @@
# 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.
=== Zope3/src/zope/app/services/pagefolder.zcml 1.2 => 1.2.4.1 ===
--- Zope3/src/zope/app/services/pagefolder.zcml:1.2 Fri Aug 22 16:02:20 2003
+++ Zope3/src/zope/app/services/pagefolder.zcml Mon Sep 8 14:21:47 2003
@@ -27,12 +27,6 @@
</content>
<adapter
- for="zope.app.interfaces.services.pagefolder.IPageFolder"
- provides="zope.app.interfaces.context.IZopeContextWrapper"
- factory="zope.app.services.pagefolder.PageFolderContextDecorator"
- />
-
-<adapter
for="zope.app.interfaces.services.pagefolder.IPageFolder"
provides="zope.app.interfaces.file.IFileFactory"
factory=".zpt.ZPTFactory"
=== Zope3/src/zope/app/services/principalannotation.py 1.9 => 1.9.24.1 ===
--- Zope3/src/zope/app/services/principalannotation.py:1.9 Sat Jun 7 01:31:58 2003
+++ Zope3/src/zope/app/services/principalannotation.py Mon Sep 8 14:21:47 2003
@@ -23,8 +23,6 @@
from persistence.dict import PersistentDict
from zodb.btrees.OOBTree import OOBTree
from zope.app.component.nextservice import queryNextService
-from zope.context import ContextMethod
-from zope.app.context import ContextWrapper
from zope.app.interfaces.annotation import IAnnotations
from zope.interface import implements
@@ -32,8 +30,9 @@
from zope.app.interfaces.services.principalannotation \
import IPrincipalAnnotationService
from zope.app.interfaces.services.service import ISimpleService
+from zope.app.container.contained import Contained
-class PrincipalAnnotationService(Persistent):
+class PrincipalAnnotationService(Persistent, Contained):
"""Stores IAnnotations for IPrinicipals.
The service ID is 'PrincipalAnnotation'.
@@ -54,7 +53,6 @@
"""
return self.getAnnotationsById(principal.getId())
- getAnnotations = ContextMethod(getAnnotations)
def getAnnotationsById(self, principalId):
"""Return object implementing IAnnotations for the given principal.
@@ -66,9 +64,8 @@
if annotations is None:
annotations = Annotations(principalId, store=self.annotations)
- return ContextWrapper(annotations, self, name=principalId)
+ return annotations
- getAnnotationsById = ContextMethod(getAnnotationsById)
def hasAnnotations(self, principal):
"""Return boolean indicating if given principal has IAnnotations."""
@@ -100,7 +97,6 @@
return annotations[key]
raise
- __getitem__ = ContextMethod(__getitem__)
def __setitem__(self, key, value):
=== Zope3/src/zope/app/services/registration.py 1.14 => 1.14.4.1 ===
--- Zope3/src/zope/app/services/registration.py:1.14 Thu Aug 21 18:33:58 2003
+++ Zope3/src/zope/app/services/registration.py Mon Sep 8 14:21:47 2003
@@ -23,7 +23,7 @@
from zope.interface import implements
from zope.app.interfaces.annotation import IAttributeAnnotatable
from zope.app.interfaces.container import IAddNotifiable, IDeleteNotifiable
-from zope.app.interfaces.container import IZopeWriteContainer
+from zope.app.interfaces.container import IRemoveSource, INameChooser
from zope.app.interfaces.dependable import IDependable, DependencyError
from zope.app.interfaces.services import registration as interfaces
from zope.app.interfaces.services.module import IModuleManager
@@ -31,8 +31,9 @@
from zope.security.checker import InterfaceChecker, CheckerPublic
from zope.security.proxy import Proxy, trustedRemoveSecurityProxy
from zope.proxy import getProxiedObject
+from zope.app.container.contained import Contained, contained
-class RegistrationStatusProperty(zapi.ContextDescriptor):
+class RegistrationStatusProperty(object):
def __get__(self, inst, klass):
if inst is None:
@@ -88,7 +89,7 @@
registry.activate(registration)
-class RegistrationStack(Persistent):
+class RegistrationStack(Persistent, Contained):
"""Registration registry implementation.
@@ -106,6 +107,9 @@
_data = () # tuple of strings (ivar)
+ def __init__(self, container):
+ self.__parent__ = container
+
def _id(self, ob):
"""Turn ob into a path relative to the site management folder."""
# Get and check relative path
@@ -128,24 +132,23 @@
return rpath
- def register(wrapped_self, registration):
- cid = wrapped_self._id(registration)
+ def register(self, registration):
+ cid = self._id(registration)
- if wrapped_self._data:
- if cid in wrapped_self._data:
+ if self._data:
+ if cid in self._data:
return # already registered
else:
# Nothing registered. Need to stick None in front so that nothing
# is active.
- wrapped_self._data = (None, )
+ self._data = (None, )
- wrapped_self._data += (cid, )
- register = zapi.ContextMethod(register)
+ self._data += (cid, )
- def unregister(wrapped_self, registration):
- cid = wrapped_self._id(registration)
+ def unregister(self, registration):
+ cid = self._id(registration)
- data = wrapped_self._data
+ data = self._data
if data:
if data[0] == cid:
# Tell it that it is no longer active
@@ -153,7 +156,7 @@
data = data[1:]
if data and data[0] is not None:
# Activate the newly active component
- sm = zapi.getServiceManager(wrapped_self)
+ sm = zapi.getServiceManager(self)
new = zapi.traverse(sm, data[0])
new.activated()
else:
@@ -165,20 +168,18 @@
data = data[:-1]
# Write data back
- wrapped_self._data = data
- unregister = zapi.ContextMethod(unregister)
+ self._data = data
- def registered(wrapped_self, registration):
- cid = wrapped_self._id(registration)
- return cid in wrapped_self._data
- registered = zapi.ContextMethod(registered)
+ def registered(self, registration):
+ cid = self._id(registration)
+ return cid in self._data
- def activate(wrapped_self, registration):
+ def activate(self, registration):
if registration is None:
cid = None
else:
- cid = wrapped_self._id(registration)
- data = wrapped_self._data
+ cid = self._id(registration)
+ data = self._data
if cid is None and not data:
return # already in the state we want
@@ -190,7 +191,7 @@
if data[0] is not None:
# Deactivate the currently active component
- sm = zapi.getServiceManager(wrapped_self)
+ sm = zapi.getServiceManager(self)
old = zapi.traverse(sm, data[0])
old.deactivated()
@@ -202,7 +203,7 @@
data = data[:-1]
# Write data back
- wrapped_self._data = data
+ self._data = data
if registration is not None:
# Tell it that it is now active
@@ -212,11 +213,10 @@
raise ValueError(
"Registration to be activated is not registered",
registration)
- activate = zapi.ContextMethod(activate)
- def deactivate(wrapped_self, registration):
- cid = wrapped_self._id(registration)
- data = wrapped_self._data
+ def deactivate(self, registration):
+ cid = self._id(registration)
+ data = self._data
if cid not in data:
raise ValueError(
@@ -238,33 +238,31 @@
if data[0] is not None:
# Activate the newly active component
- sm = zapi.getServiceManager(wrapped_self)
+ sm = zapi.getServiceManager(self)
new = zapi.traverse(sm, data[0])
new.activated()
# Write data back
- wrapped_self._data = data
- deactivate = zapi.ContextMethod(deactivate)
+ self._data = data
- def active(wrapped_self):
- if wrapped_self._data:
- path = wrapped_self._data[0]
+ def active(self):
+ if self._data:
+ path = self._data[0]
if path is not None:
# Make sure we can zapi.traverse to it.
- sm = zapi.getServiceManager(wrapped_self)
+ sm = zapi.getServiceManager(self)
registration = zapi.traverse(sm, path)
return registration
return None
- active = zapi.ContextMethod(active)
def __nonzero__(self):
return bool(self._data)
- def info(wrapped_self, keep_dummy=False):
- sm = zapi.getServiceManager(wrapped_self)
+ def info(self, keep_dummy=False):
+ sm = zapi.getServiceManager(self)
- data = wrapped_self._data
+ data = self._data
if None not in data:
data += (None,)
@@ -282,10 +280,9 @@
result = [x for x in result if x['id']]
return result
- info = zapi.ContextMethod(info)
-class SimpleRegistration(Persistent):
+class SimpleRegistration(Persistent, Contained):
"""Registration objects that just contain registration data
Classes that derive from this must make sure they implement
@@ -370,8 +367,8 @@
def implementationSummary(self):
return self.componentPath
- def getComponent(wrapped_self):
- service_manager = zapi.getServiceManager(wrapped_self)
+ def getComponent(self):
+ service_manager = zapi.getServiceManager(self)
# The user of the registration object may not have permission
# to traverse to the component. Yet they should be able to
@@ -388,7 +385,7 @@
# traverses from there, so we need to make sure the
# physical root isn't proxied.
- path = wrapped_self.componentPath
+ path = self.componentPath
# Get the root and unproxy it
if path.startswith("/"):
# Absolute path
@@ -396,25 +393,23 @@
component = zapi.traverse(root, path)
else:
# Relative path.
- ancestor = zapi.getWrapperContainer(
- zapi.getWrapperContainer(wrapped_self))
+ ancestor = self.__parent__.__parent__
component = zapi.traverse(ancestor, path)
- if wrapped_self.permission:
+ 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 = trustedRemoveSecurityProxy(component)
- interface = wrapped_self.getInterface()
+ interface = self.getInterface()
- checker = InterfaceChecker(interface, wrapped_self.permission)
+ checker = InterfaceChecker(interface, self.permission)
component = Proxy(component, checker)
return component
- getComponent = zapi.ContextMethod(getComponent)
def afterAddHook(self, registration, container):
"See IAddNotifiable"
@@ -461,36 +456,32 @@
self._bindings = {}
super(NameRegistry, self).__init__(*args, **kw)
- def queryRegistrationsFor(wrapped_self, cfg, default=None):
+ def queryRegistrationsFor(self, cfg, default=None):
"""See IRegistry"""
- return wrapped_self.queryRegistrations(cfg.name, default)
- queryRegistrationsFor = zapi.ContextMethod(queryRegistrationsFor)
+ return self.queryRegistrations(cfg.name, default)
- def queryRegistrations(wrapped_self, name, default=None):
+ def queryRegistrations(self, name, default=None):
"""See INameRegistry"""
- registry = wrapped_self._bindings.get(name, default)
- return zapi.ContextWrapper(registry, wrapped_self)
- queryRegistrations = zapi.ContextMethod(queryRegistrations)
-
- def createRegistrationsFor(wrapped_self, cfg):
+ return self._bindings.get(name, default)
+
+ def createRegistrationsFor(self, cfg):
"""See IRegistry"""
- return wrapped_self.createRegistrations(cfg.name)
- createRegistrationsFor = zapi.ContextMethod(createRegistrationsFor)
+ return self.createRegistrations(cfg.name)
- def createRegistrations(wrapped_self, name):
+ def createRegistrations(self, name):
"""See INameRegistry"""
try:
- registry = wrapped_self._bindings[name]
+ registry = self._bindings[name]
except KeyError:
- wrapped_self._bindings[name] = registry = RegistrationStack()
- wrapped_self._p_changed = 1
- return zapi.ContextWrapper(registry, wrapped_self)
- createRegistrations = zapi.ContextMethod(createRegistrations)
+ registry = RegistrationStack(self)
+ self._bindings[name] = registry
+ self._p_changed = 1
+ return registry
- def listRegistrationNames(wrapped_self):
+ def listRegistrationNames(self):
"""See INameRegistry"""
- return filter(wrapped_self._bindings.get,
- wrapped_self._bindings.keys())
+ return filter(self._bindings.get,
+ self._bindings.keys())
class NameComponentRegistry(NameRegistry):
@@ -498,15 +489,14 @@
"""
implements(interfaces.INameComponentRegistry)
- def queryActiveComponent(wrapped_self, name, default=None):
+ def queryActiveComponent(self, name, default=None):
"""See INameComponentRegistry"""
- registry = wrapped_self.queryRegistrations(name)
+ registry = self.queryRegistrations(name)
if registry:
registration = registry.active()
if registration is not None:
return registration.getComponent()
return default
- queryActiveComponent = zapi.ContextMethod(queryActiveComponent)
from zope.app.dependable import PathSetAnnotation
@@ -531,17 +521,17 @@
usages = PathSetAnnotation.getPaths
-class RegistrationManager(Persistent):
+class RegistrationManager(Persistent, Contained):
"""Registration manager
Manages registrations within a package.
"""
- implements(interfaces.IRegistrationManager, IDeleteNotifiable)
+ implements(interfaces.IRegistrationManager, IDeleteNotifiable,
+ INameChooser)
def __init__(self):
self._data = ()
- self._next = 0
def __getitem__(self, key):
"See IItemContainer"
@@ -582,29 +572,31 @@
def setObject(self, key, object):
"See IWriteContainer"
- self._next += 1
- if key:
+ if not key:
+ key = self.chooseName(key, object)
+ else:
if key in self:
raise DuplicationError("key is already registered", key)
- try:
- n = int(key)
- except ValueError:
- pass
- else:
- if n > self._next:
- self._next = n
- else:
- key = str(self._next)
- while key in self:
- self._next += 1
- key = str(self._next)
+
+ object = contained(object, self, key)
self._data += ((key, object), )
return key
+ def chooseName(self, name, object):
+ if not name:
+ name = object.__class__.__name__
+
+ i = 1
+ n = name
+ while n in self:
+ i += 1
+ n = name + str(i)
+
+ return n
+
def __delitem__(self, key):
"See IWriteContainer"
- if key not in self:
- raise KeyError, key
+ uncontained(self[key])
self._data = tuple(
[item
for item in self._data
@@ -664,9 +656,9 @@
def beforeDeleteHook(self, object, container):
assert object == self
- container = zapi.getAdapter(object, IZopeWriteContainer)
+ container = zapi.getAdapter(object, IRemoveSource)
for k, v in self._data:
- del container[k]
+ container.removeObject(k)
class RegistrationManagerContainer(object):
@@ -677,7 +669,10 @@
def __init__(self):
super(RegistrationManagerContainer, self).__init__()
- self.setObject('RegistrationManager', RegistrationManager())
+ rm = RegistrationManager()
+ rm.__parent__ = self
+ rm.__name__ = 'RegistrationManager'
+ self.setObject(rm.__name__, rm)
def __delitem__(self, name):
"""Delete an item, but not if it's the last registration manager
@@ -701,11 +696,10 @@
item = self[name]
if interfaces.IRegistrationManager.isImplementedBy(item):
# We found one. Get it in context
- return zapi.ContextWrapper(item, self, name=name)
+ return item
else:
raise interfaces.NoRegistrationManagerError(
"Couldn't find an registration manager")
- getRegistrationManager = zapi.ContextMethod(getRegistrationManager)
def findModule(self, name):
# Used by the persistent modules import hook
@@ -724,8 +718,9 @@
if IModuleManager.isImplementedBy(manager):
return manager.getModule()
- # See if our container is a RegistrationManagerContainer:
- c = zapi.getWrapperContainer(self)
+
+ # See if out container is a RegistrationManagerContainer:
+ c = self.__parent__
if interfaces.IRegistrationManagerContainer.isImplementedBy(c):
return c.findModule(name)
@@ -736,14 +731,12 @@
raise ImportError(name)
- findModule = zapi.ContextMethod(findModule)
def resolve(self, name):
l = name.rfind('.')
mod = self.findModule(name[:l])
return getattr(mod, name[l+1:])
- resolve = zapi.ContextMethod(resolve)
from zope.xmlpickle import dumps, loads
=== Zope3/src/zope/app/services/role.py 1.6 => 1.6.24.1 ===
--- Zope3/src/zope/app/services/role.py:1.6 Thu Jun 5 08:03:17 2003
+++ Zope3/src/zope/app/services/role.py Mon Sep 8 14:21:47 2003
@@ -22,7 +22,6 @@
from zope.app.container.btree import BTreeContainer
from zope.app.interfaces.security import IRoleService
from zope.app.interfaces.container import IContainer
-from zope.context import ContextMethod
from zope.app.component.nextservice import getNextService
from zope.app.interfaces.services.service import ISimpleService
from zope.interface import implements
@@ -47,7 +46,6 @@
if sv:
return sv.getRole(rid)
raise # will be original Key Error
- getRole = ContextMethod(getRole)
def getRoles(wrapped_self):
'''See interface IRoleService'''
@@ -56,4 +54,3 @@
if roleserv:
roles.extend(roleserv.getRoles())
return roles
- getRoles = ContextMethod(getRoles)
=== Zope3/src/zope/app/services/service.py 1.29 => 1.29.18.1 ===
--- Zope3/src/zope/app/services/service.py:1.29 Fri Jul 4 06:59:16 2003
+++ Zope3/src/zope/app/services/service.py Mon Sep 8 14:21:47 2003
@@ -35,8 +35,6 @@
from zope.component import getServiceManager
from zope.component.exceptions import ComponentLookupError
-from zope.context import ContextMethod
-from zope.app.context import ContextWrapper
from zope.proxy import removeAllProxies
from zope.app.component.nextservice import getNextService
@@ -53,15 +51,19 @@
from zope.app.interfaces.services.service import ILocalService
from zope.app.traversing import getPath
+from zope.app.container.contained import Contained
-class ServiceManager(PersistentModuleRegistry, NameComponentRegistry):
+class ServiceManager(PersistentModuleRegistry, NameComponentRegistry,
+ Contained):
implements(IServiceManager, IContainer)
def __init__(self):
PersistentModuleRegistry.__init__(self)
NameComponentRegistry.__init__(self)
- self.Packages = SiteManagementFolders()
+ self.Packages = SiteManagementFolders(self)
+ self.Packages.__parent__ = self
+ self.Packages.__name__ = 'Packages'
def getServiceDefinitions(wrapped_self):
"See IServiceService"
@@ -74,7 +76,6 @@
else: serviceDefs = {}
return serviceDefs
- getServiceDefinitions = ContextMethod(getServiceDefinitions)
def queryService(wrapped_self, name, default=None):
"See IServiceService"
@@ -82,7 +83,6 @@
return wrapped_self.getService(name)
except ComponentLookupError:
return default
- queryService = ContextMethod(queryService)
def getService(wrapped_self, name):
"See IServiceService"
@@ -108,7 +108,6 @@
wrapped_self._v_calling = 0
return getNextService(wrapped_self, name)
- getService = ContextMethod(getService)
def queryLocalService(wrapped_self, name, default=None):
@@ -137,7 +136,6 @@
return default
- queryLocalService = ContextMethod(queryLocalService)
def getInterfaceFor(wrapped_self, service_type):
@@ -147,22 +145,20 @@
return interface
raise NameError(service_type)
- getInterfaceFor = ContextMethod(getInterfaceFor)
def queryComponent(self, type=None, filter=None, all=0):
local = []
path = getPath(self)
for pkg_name in self:
- package = ContextWrapper(self[pkg_name], self, name=pkg_name)
+ package = self[pkg_name]
for name in package:
component = package[name]
if type is not None and not type.isImplementedBy(component):
continue
if filter is not None and not filter(component):
continue
- wrapper = ContextWrapper(component, package, name=name)
local.append({'path': "%s/%s/%s" % (path, pkg_name, name),
- 'component': wrapper,
+ 'component': component,
})
if all:
@@ -174,7 +170,6 @@
return local
- queryComponent = ContextMethod(queryComponent)
# We provide a mapping interface for traversal, but we only expose
# local services through the mapping interface.
@@ -196,7 +191,6 @@
return wrapped_self.Packages.get(key, default)
- get = ContextMethod(get)
def __contains__(self, key):
"See Interface.Common.Mapping.IReadMapping"
@@ -212,12 +206,10 @@
def values(self):
return map(self.get, self.keys())
- values = ContextMethod(values)
def items(self):
return [(key, self.get(key)) for key in self.keys()]
- items = ContextMethod(items)
def __len__(self):
return len(self.Packages)
@@ -244,7 +236,6 @@
# direct way to ask if sm is the global service manager.
return None
return findModule(name)
- findModule = ContextMethod(findModule)
def __import(wrapped_self, module_name):
@@ -255,7 +246,6 @@
raise ImportError(module_name)
return mod
- __import = ContextMethod(__import)
class ServiceRegistration(NamedComponentRegistration):
@@ -272,8 +262,8 @@
super(ServiceRegistration, self).__init__(name, path)
if context is not None:
# Check that the object implements stuff we need
- wrapped_self = ContextWrapper(self, context)
- service = wrapped_self.getComponent()
+ self.__parent__ = context
+ service = self.getComponent()
if not ILocalService.isImplementedBy(service):
raise TypeError("service %r doesn't implement ILocalService" %
service)
@@ -283,21 +273,18 @@
service_manager = getServiceManager(self)
return service_manager.getInterfaceFor(self.name)
- getInterface = ContextMethod(getInterface)
def activated(self):
service = self.getComponent()
if IBindingAware.isImplementedBy(service):
service.bound(self.name)
- activated = ContextMethod(activated)
def deactivated(self):
service = self.getComponent()
if IBindingAware.isImplementedBy(service):
service.unbound(self.name)
- deactivated = ContextMethod(deactivated)
def usageSummary(self):
return self.name + " Service"
=== Zope3/src/zope/app/services/servicecontainer.py 1.5 => 1.5.2.1 ===
--- Zope3/src/zope/app/services/servicecontainer.py:1.5 Tue Sep 2 16:46:50 2003
+++ Zope3/src/zope/app/services/servicecontainer.py Mon Sep 8 14:21:47 2003
@@ -19,10 +19,12 @@
from zope.component.exceptions import ComponentLookupError
from zope.app.interfaces.services.service import IPossibleSite, ISite
from zope.component.interfaces import IServiceService
+from zope.interface import implements
+from zope.app.container.contained import Contained
from zope.app import zapi
import zope.interface
-class ServiceManagerContainer:
+class ServiceManagerContainer(Contained):
"""Implement access to the service manager (++etc++site).
@@ -46,6 +48,8 @@
if IServiceService.isImplementedBy(sm):
self.__sm = sm
+ sm.__name__ = '++etc++site'
+ sm.__parent__ = self
else:
raise ValueError('setSiteManager requires an IServiceService')
=== Zope3/src/zope/app/services/session.py 1.10 => 1.10.24.1 ===
--- Zope3/src/zope/app/services/session.py:1.10 Sat Jun 7 01:31:59 2003
+++ Zope3/src/zope/app/services/session.py Mon Sep 8 14:21:47 2003
@@ -32,7 +32,7 @@
from zope.app.interfaces.services.session import ISessionService
from zope.app.interfaces.services.session import IConfigureSessionService
from zope.app.interfaces.services.service import ISimpleService
-
+from zope.app.container.contained import Contained
cookieSafeTrans = string.maketrans("+/", "-.")
@@ -41,7 +41,7 @@
return s.encode("base64")[:-2].translate(cookieSafeTrans)
-class CookieSessionService(Persistent):
+class CookieSessionService(Persistent, Contained):
"""Session service implemented using cookies."""
implements(ISessionService, IConfigureSessionService, ISimpleService)
=== Zope3/src/zope/app/services/utility.py 1.16 => 1.16.6.1 ===
--- Zope3/src/zope/app/services/utility.py:1.16 Tue Aug 19 19:11:05 2003
+++ Zope3/src/zope/app/services/utility.py Mon Sep 8 14:21:47 2003
@@ -29,9 +29,8 @@
RegistrationStack, ComponentRegistration
from zope.component.exceptions import ComponentLookupError
from zope.interface.implementor import ImplementorRegistry
-from zope.context import ContextMethod
-from zope.app.context import ContextWrapper
from zope.proxy import removeAllProxies
+from zope.app.container.contained import Contained
class LocalUtilityService(Persistent):
@@ -46,7 +45,6 @@
if utility is None:
raise ComponentLookupError("utility", interface, name)
return utility
- getUtility = ContextMethod(getUtility)
def queryUtility(self, interface, default=None, name=''):
"""See zope.component.interfaces.IUtilityService"""
@@ -58,7 +56,6 @@
next = getNextService(self, Utilities)
return next.queryUtility(interface, default, name)
- queryUtility = ContextMethod(queryUtility)
def getUtilitiesFor(self, interface):
"""See zope.component.interfaces.IUtilityService"""
@@ -70,14 +67,12 @@
if utility[0] not in names:
utilities.append(utility)
return utilities
- getUtilitiesFor = ContextMethod(getUtilitiesFor)
def getLocalUtilitiesFor(self, interface):
"""See zope.app.interfaces.services.ILocalUtilityService"""
utilities = []
for name in self._utilities:
for iface, cr in self._utilities[name].getRegisteredMatching():
- cr = ContextWrapper(cr, self)
if not cr or cr.active() is None:
continue
utility = cr.active().getComponent()
@@ -86,7 +81,6 @@
continue
utilities.append((name, utility))
return utilities
- getLocalUtilitiesFor = ContextMethod(getLocalUtilitiesFor)
def getRegisteredMatching(self, interface=None, name=None):
@@ -100,16 +94,14 @@
continue
if name is not None and reg_name.find(name) < 0:
continue
- L.append((iface, reg_name, ContextWrapper(cr, self)))
+ L.append((iface, reg_name, cr))
return L
- getRegisteredMatching = ContextMethod(getRegisteredMatching)
def queryRegistrationsFor(self, registration, default=None):
"""zope.app.interfaces.services.registration.IRegistry"""
return self.queryRegistrations(registration.name,
registration.interface,
default)
- queryRegistrationsFor = ContextMethod(queryRegistrationsFor)
def queryRegistrations(self, name, interface, default=None):
"""zope.app.interfaces.services.registration.IRegistry"""
@@ -120,15 +112,13 @@
if stack is None:
return default
- return ContextWrapper(stack, self)
- queryRegistrations = ContextMethod(queryRegistrations)
+ return stack
def createRegistrationsFor(self, registration):
"""zope.app.interfaces.services.registration.IRegistry"""
return self.createRegistrations(registration.name,
registration.interface)
- createRegistrationsFor = ContextMethod(createRegistrationsFor)
def createRegistrations(self, name, interface):
"""zope.app.interfaces.services.registration.IRegistry"""
@@ -142,8 +132,7 @@
stack = RegistrationStack()
utilities.register(interface, stack)
- return ContextWrapper(stack, self)
- createRegistrations = ContextMethod(createRegistrations)
+ return stack
class UtilityRegistration(ComponentRegistration):
=== Zope3/src/zope/app/services/view.py 1.34 => 1.34.6.1 ===
--- Zope3/src/zope/app/services/view.py:1.34 Wed Aug 20 14:21:12 2003
+++ Zope3/src/zope/app/services/view.py Mon Sep 8 14:21:47 2003
@@ -49,8 +49,9 @@
from zope.app.services.adapter import PersistentAdapterRegistry
from zope.configuration.exceptions import ConfigurationError
from zope.app.interfaces.services.service import ISimpleService
+from zope.app.container.contained import Contained
-class ViewService(Persistent):
+class ViewService(Persistent, Contained):
implements(IViewService, ILocalViewService, IRegistry, ISimpleService,
IInterfaceBasedRegistry)
@@ -58,9 +59,6 @@
def __init__(self):
self._layers = PersistentDict()
- # All the methods defined here are context methods
- zapi.ContextAwareDescriptors()
-
def queryRegistrationsFor(self, registration, default=None):
"See IRegistry"
return self.queryRegistrations(
@@ -85,7 +83,7 @@
if registry is None:
return default
- return zapi.ContextWrapper(registry, self)
+ return registry
def createRegistrationsFor(self, registration):
"See IRegistry"
@@ -110,10 +108,10 @@
forInterface, presentationType)
if registry is None:
- registry = RegistrationStack()
+ registry = RegistrationStack(self)
adapter_registry.register(forInterface, presentationType, registry)
- return zapi.ContextWrapper(registry, self)
+ return registry
def getView(self, object, name, request):
view = self.queryView(object, name, request)
@@ -137,14 +135,12 @@
registry = reg.getForObject(
object, type,
- filter = lambda registry:
- zapi.ContextWrapper(registry, self).active(),
+ filter = lambda registry: registry.active(),
)
if registry is None:
continue
- registry = zapi.ContextWrapper(registry, self)
view = registry.active().getView(object, request)
return view
@@ -206,7 +202,7 @@
def getRegistrationsForInterface(self, iface):
for t in self.getRegisteredMatching(required_interfaces=[iface]):
# XXX getRegisteredMatching ought to return a wrapped object
- reg = zapi.ContextWrapper(t[2], self) # t[2] is registration stack
+ reg = t[2]
for info in reg.info():
yield info["registration"]
@@ -285,11 +281,10 @@
self.permission = permission
def getView(self, object, request):
- folder = zapi.getWrapperContainer(zapi.getWrapperContainer(self))
+ folder = self.__parent__.__parent__
factory = folder.resolve(self.class_)
return factory(object, request)
- getView = zapi.ContextMethod(getView)
def usageSummary(self):
if self.forInterface is None:
@@ -377,7 +372,7 @@
sm = zapi.getServiceManager(self)
if self.class_:
- folder = zapi.getWrapperContainer(zapi.getWrapperContainer(self))
+ folder = self.__parent__.__parent__
class_ = folder.resolve(self.class_)
class_ = type(class_.__name__, (class_, DefaultClass), {})
else:
@@ -398,7 +393,6 @@
return ProxyFactory(template, checker)
- getView = zapi.ContextMethod(getView)
class DefaultClass:
=== Zope3/src/zope/app/services/zpt.py 1.13 => 1.13.24.1 ===
--- Zope3/src/zope/app/services/zpt.py:1.13 Sat Jun 7 01:31:59 2003
+++ Zope3/src/zope/app/services/zpt.py Mon Sep 8 14:21:47 2003
@@ -28,8 +28,9 @@
from zope.app.interfaces.file import IReadFile, IWriteFile, IFileFactory
from zope.app.fssync.classes import ObjectEntryAdapter, AttrMapping
from zope.app.interfaces.fssync import IObjectFile
+from zope.app.container.contained import Contained
-class ZPTTemplate(AppPT, PageTemplate, Persistent):
+class ZPTTemplate(AppPT, PageTemplate, Persistent, Contained):
implements(IZPTTemplate)
More information about the Zope3-Checkins
mailing list