[Zope3-checkins] CVS: Zope3/src/zope/app/services -
auth.py:1.19.24.3 folder.py:1.13.6.5 hub.py:1.20.8.3
menu.py:1.6.4.4 registration.py:1.14.4.7 service.py:1.29.18.3
Jim Fulton
jim at zope.com
Mon Sep 15 14:13:09 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv15511/src/zope/app/services
Modified Files:
Tag: parentgeddon-branch
auth.py folder.py hub.py menu.py registration.py service.py
Log Message:
Got lots of tests to pass.
Added a setitem helper function to be used to help satisfy container
contracts.
=== Zope3/src/zope/app/services/auth.py 1.19.24.2 => 1.19.24.3 ===
--- Zope3/src/zope/app/services/auth.py:1.19.24.2 Fri Sep 12 15:15:33 2003
+++ Zope3/src/zope/app/services/auth.py Mon Sep 15 14:12:38 2003
@@ -35,7 +35,7 @@
from zope.app.component.nextservice import getNextService
from zope.app.interfaces.services.service import ISimpleService
from zope.interface import implements
-from zope.app.container.contained import Contained
+from zope.app.container.contained import Contained, setitem, uncontained
class DuplicateLogin(Exception):
@@ -109,6 +109,9 @@
return self._usersbyid[id]
def __setitem__(self, key, object):
+ setitem(self, self.__setitem, key, object)
+
+ def __setitem(self, key, object):
'See IWriteContainer'
# XXX I think this should generate an id if blank is passed. (RDM)
if not isinstance(key, (str, unicode)):
=== Zope3/src/zope/app/services/folder.py 1.13.6.4 => 1.13.6.5 ===
--- Zope3/src/zope/app/services/folder.py:1.13.6.4 Fri Sep 12 16:03:06 2003
+++ Zope3/src/zope/app/services/folder.py Mon Sep 15 14:12:38 2003
@@ -28,67 +28,11 @@
from zope.app.services.registration import RegistrationManagerContainer
from zope.app.traversing import getPath
from zope.interface import implements
+from zope.app.container.contained import setitem
class SiteManagementFolder(RegistrationManagerContainer, BTreeContainer):
implements(ISiteManagementFolder)
-
-class SiteManagementFolders(BTreeContainer):
- implements(ISiteManagementFolders)
-
- def __init__(self, container):
- self.__parent__ = container
- super(SiteManagementFolders, self).__init__()
- f = SiteManagementFolder()
- f.__name__ = 'default'
- self['default'] = f
-
- def queryComponent(self, type=None, filter=None, all=0):
- local = []
- path = getPath(self)
- for pkg_name in self:
- 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
- local.append({'path': "%s/%s/%s" % (path, pkg_name, name),
- 'component': component,
- })
-
- if all:
- next_service_manager = getNextServiceManager(self)
- if IComponentManager.isImplementedBy(next_service_manager):
- next_service_manager.queryComponent(type, filter, all)
-
- local += list(all)
-
- return local
-
- def __setitem__(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")
-
- # XXX We want to do super(...)[name] = obj, but the setitem
- # slot doesn't get handled properly in Python 2.2.x and 2.3. ;-(
- #super(SiteManagementFolders, self)[name] = obj
- # We can name __setitem__ explicitly, though:
- super(SiteManagementFolders, self).__setitem__(name, obj)
-
- # We want out items to be virtually contained in our container
- # We have to do this after calling the superclass __setitem__
- # otherwise, it would be overwritten.
- obj.__parent__ = self.__parent__
-
- return name
-
class SMFolderFactory(object):
implements(IDirectoryFactory)
@@ -101,7 +45,12 @@
# XXX Backward compatability. This is needed to support old pickles.
Package = SiteManagementFolder
+
+class SiteManagementFolders:
+ pass
Packages = SiteManagementFolders
+
import sys
+
sys.modules['zope.app.services.package'
] = sys.modules['zope.app.services.folder']
=== Zope3/src/zope/app/services/hub.py 1.20.8.2 => 1.20.8.3 ===
--- Zope3/src/zope/app/services/hub.py:1.20.8.2 Fri Sep 12 15:15:33 2003
+++ Zope3/src/zope/app/services/hub.py Mon Sep 15 14:12:38 2003
@@ -22,6 +22,7 @@
import random
+from zope.app import zapi
from zodb.btrees.IOBTree import IOBTree
from zodb.btrees.OIBTree import OIBTree
@@ -202,20 +203,43 @@
# unicode pathslash --> int
self.__path_to_hubid = OIBTree()
- def notify(wrapped_self, event):
+ def notify(self, event):
'''See interface ISubscriber'''
- clean_self = removeAllProxies(wrapped_self)
- clean_self._notify(wrapped_self, event)
+ self._notify(self, event)
+
+ # XXX all of these "if"s are BS. We should subscribe to the
+ # different kinds of events independently.
+
+
if IObjectEvent.isImplementedBy(event):
# generate NotificationHubEvents only if object is known
# ie registered
+
if IObjectMovedEvent.isImplementedBy(event):
+ if not (event.oldParent and event.oldName):
+ # add event, not interested
+ return
+
+ # We have a move or remove. See if we know anything about it:
pathslash = canonicalSlash(event.oldParent, event.oldName)
- hubid = clean_self.__path_to_hubid.get(pathslash)
- if hubid is not None:
+ hubid = self.__path_to_hubid.get(pathslash)
+ if hubid is None:
+ # Nope
+ return
+
+ if not (event.newParent and event.newName):
+ # Removed event
+ del self.__hubid_to_path[hubid]
+ del self.__path_to_hubid[pathslash]
+ # send out IObjectRemovedHubEvent to plugins
+ event = ObjectRemovedHubEvent(
+ event.object, hubid, pathslash[:-1], event.object)
+ self._notify(self, event)
+ else:
+ # Move
new_pathslash = canonicalSlash(
event.newParent, event.newName)
- path_to_hubid = clean_self.__path_to_hubid
+ path_to_hubid = self.__path_to_hubid
if path_to_hubid.has_key(new_pathslash):
raise ObjectHubError(
'Cannot move to location %s, '
@@ -224,33 +248,22 @@
hubid = path_to_hubid[pathslash]
del path_to_hubid[pathslash]
path_to_hubid[new_pathslash] = hubid
- clean_self.__hubid_to_path[hubid] = new_pathslash
+ self.__hubid_to_path[hubid] = new_pathslash
# send out IObjectMovedHubEvent to plugins
event = ObjectMovedHubEvent(
- wrapped_self, hubid, pathslash[:-1],
+ self, hubid, pathslash[:-1],
new_pathslash[:-1], event.object)
- clean_self._notify(wrapped_self, event)
- elif IObjectCreatedEvent.isImplementedBy(event):
- # a newly created object that has not been added to a
- # container yet has no location. So, we're not interested in
- # it.
- pass
- else:
- pathslash = canonicalSlash(event.newParent, event.newName)
- hubid = clean_self.__path_to_hubid.get(pathslash)
- if hubid is not None:
- if IObjectModifiedEvent.isImplementedBy(event):
- # send out IObjectModifiedHubEvent to plugins
- event = ObjectModifiedHubEvent(
- wrapped_self, hubid, pathslash[:-1], event.object)
- clean_self._notify(wrapped_self, event)
- elif IObjectRemovedEvent.isImplementedBy(event):
- del clean_self.__hubid_to_path[hubid]
- del clean_self.__path_to_hubid[pathslash]
- # send out IObjectRemovedHubEvent to plugins
- event = ObjectRemovedHubEvent(
- event.object, hubid, pathslash[:-1], event.object)
- clean_self._notify(wrapped_self, event)
+ self._notify(self, event)
+
+ elif IObjectModifiedEvent.isImplementedBy(event):
+ # send out IObjectModifiedHubEvent to plugins
+ pathslash = canonicalSlash(zapi.getPath(event.object))
+ hubid = self.__path_to_hubid.get(pathslash)
+ if hubid is None:
+ return
+ event = ObjectModifiedHubEvent(
+ self, hubid, pathslash[:-1], event.object)
+ self._notify(self, event)
def getHubId(self, path_or_object):
'''See interface ILocalObjectHub'''
@@ -273,16 +286,16 @@
except KeyError:
raise NotFoundError(hubid)
- def getObject(wrapped_self, hubid):
+ def getObject(self, hubid):
'''See interface IObjectHub'''
- path = wrapped_self.getPath(hubid)
- adapter = getAdapter(wrapped_self, ITraverser)
- wrapped_self._verifyPath(path, adapter)
+ path = self.getPath(hubid)
+ adapter = getAdapter(self, ITraverser)
+ self._verifyPath(path, adapter)
return adapter.traverse(path)
- def register(wrapped_self, path_or_object):
+ def register(self, path_or_object):
'''See interface ILocalObjectHub'''
- clean_self = removeAllProxies(wrapped_self)
+
# XXX Need a new unit test for this; previously we tested
# whether it's wrapped, which is wrong because the root
# isn't wrapped (and it certainly makes sense to want to
@@ -296,32 +309,31 @@
pathslash = canonicalSlash(path)
- path_to_hubid = clean_self.__path_to_hubid
+ path_to_hubid = self.__path_to_hubid
if path_to_hubid.has_key(pathslash):
raise ObjectHubError('path %s already in object hub' % path)
- hubid = clean_self._generateHubId(pathslash)
+ hubid = self._generateHubId(pathslash)
path_to_hubid[pathslash] = hubid
# send out IObjectRegisteredHubEvent to plugins
event = ObjectRegisteredHubEvent(
- wrapped_self, hubid, pathslash[:-1], obj)
- clean_self._notify(wrapped_self, event)
+ self, hubid, pathslash[:-1], obj)
+ self._notify(self, event)
return hubid
- def unregister(wrapped_self, path_or_object_or_hubid):
+ def unregister(self, path_or_object_or_hubid):
'''See interface ILocalObjectHub'''
- clean_self = removeAllProxies(wrapped_self)
if isinstance(path_or_object_or_hubid, (unicode, str)):
path = canonicalPath(path_or_object_or_hubid)
elif isinstance(path_or_object_or_hubid, int):
- path = clean_self.getPath(path_or_object_or_hubid)
+ path = self.getPath(path_or_object_or_hubid)
else:
path = getPath(path_or_object_or_hubid)
pathslash = canonicalSlash(path)
- path_to_hubid = clean_self.__path_to_hubid
- hubid_to_path = clean_self.__hubid_to_path
+ path_to_hubid = self.__path_to_hubid
+ hubid_to_path = self.__hubid_to_path
try:
hubid = path_to_hubid[pathslash]
except KeyError:
@@ -332,8 +344,8 @@
# send out IObjectUnregisteredHubEvent to plugins
event = ObjectUnregisteredHubEvent(
- wrapped_self, hubid, pathslash[:-1])
- clean_self._notify(wrapped_self, event)
+ self, hubid, pathslash[:-1])
+ self._notify(self, event)
def numRegistrations(self):
"""See interface IObjectHub"""
@@ -361,11 +373,11 @@
min=pathslash, max=pathslash[:-1]+u'0', excludemax=True):
yield pathslash[:-1], hubId
- def iterObjectRegistrations(wrapped_self):
+ def iterObjectRegistrations(self):
"""See interface IHubEventChannel"""
- traverser = getAdapter(wrapped_self, ITraverser)
- for path, hubId in wrapped_self.iterRegistrations():
- yield (path, hubId, wrapped_self._safeTraverse(path, traverser))
+ traverser = getAdapter(self, ITraverser)
+ for path, hubId in self.iterRegistrations():
+ yield (path, hubId, self._safeTraverse(path, traverser))
############################################################
@@ -380,13 +392,13 @@
return index
- def _verifyPath(wrapped_self, path, traverser=None):
+ def _verifyPath(self, path, traverser=None):
if traverser is None:
- traverser = getAdapter(wrapped_self, ITraverser)
+ traverser = getAdapter(self, ITraverser)
try:
traverser.traverse(path)
except NotFoundError, e:
- wrapped_self.unregister(path)
+ self.unregister(path)
raise e
@@ -396,15 +408,15 @@
except NotFoundError:
return None
- def unregisterMissingObjects(wrapped_self):
+ def unregisterMissingObjects(self):
# XXX temporary method for clearing missing objects - remove when
# proper unregistration mechanisms are added.
missing = []
- for object in wrapped_self.iterObjectRegistrations():
+ for object in self.iterObjectRegistrations():
if object[2] is None:
missing.append(object[0])
for path in missing:
- wrapped_self.unregister(path)
+ self.unregister(path)
return len(missing)
@@ -430,7 +442,7 @@
implements(ISubscriptionControl, ISubscriber)
- def notify(wrapped_self, event):
+ def notify(self, event):
"""An event occured. Perhaps register this object with the hub."""
# XXX quick hack to make sure we *only* register on add events
@@ -439,37 +451,37 @@
# have it correct now.
if event.__class__ is ObjectAddedEvent:
- hub = getService(wrapped_self, HubIds)
- wrapped_self._registerObject(event.object, hub)
+ hub = getService(self, HubIds)
+ self._registerObject(event.object, hub)
currentlySubscribed = False # Default subscription state
- def subscribe(wrapped_self):
- if wrapped_self.currentlySubscribed:
+ def subscribe(self):
+ if self.currentlySubscribed:
raise RuntimeError, "already subscribed; please unsubscribe first"
# we subscribe to the HubIds service so that we're
# guaranteed to get exactly the events *that* service receives.
- events = getService(wrapped_self, EventSubscription)
- events.subscribe(wrapped_self, IObjectAddedEvent)
- wrapped_self.currentlySubscribed = True
+ events = getService(self, EventSubscription)
+ events.subscribe(self, IObjectAddedEvent)
+ self.currentlySubscribed = True
- def unsubscribe(wrapped_self):
- if not wrapped_self.currentlySubscribed:
+ def unsubscribe(self):
+ if not self.currentlySubscribed:
raise RuntimeError, "not subscribed; please subscribe first"
- events = getService(wrapped_self, EventSubscription)
- events.unsubscribe(wrapped_self, IObjectAddedEvent)
- wrapped_self.currentlySubscribed = False
+ events = getService(self, EventSubscription)
+ events.unsubscribe(self, IObjectAddedEvent)
+ self.currentlySubscribed = False
def isSubscribed(self):
return self.currentlySubscribed
- def registerExisting(wrapped_self):
- object = findContentObject(wrapped_self)
- hub = getService(wrapped_self, HubIds)
- wrapped_self._registerTree(object, hub)
+ def registerExisting(self):
+ object = findContentObject(self)
+ hub = getService(self, HubIds)
+ self._registerTree(object, hub)
- def _registerTree(wrapped_self, object, hub):
- wrapped_self._registerObject(object, hub)
+ def _registerTree(self, object, hub):
+ self._registerObject(object, hub)
# XXX Policy decision: only traverse into folders
if not IFolder.isImplementedBy(object):
return
@@ -478,9 +490,9 @@
traversable = getAdapter(object, ITraversable)
for name in names:
sub_object = traverseName(object, name, traversable=traversable)
- wrapped_self._registerTree(sub_object, hub)
+ self._registerTree(sub_object, hub)
- def _registerObject(wrapped_self, location, hub):
+ def _registerObject(self, location, hub):
# XXX Policy decision: register absolutely everything
try:
hub.register(location)
=== Zope3/src/zope/app/services/menu.py 1.6.4.3 => 1.6.4.4 ===
--- Zope3/src/zope/app/services/menu.py:1.6.4.3 Fri Sep 12 15:15:33 2003
+++ Zope3/src/zope/app/services/menu.py Mon Sep 15 14:12:38 2003
@@ -101,7 +101,7 @@
while key in self:
self._next += 1
key = str(self._next)
- super(LocalBrowserMenu, self)[key] = object
+ super(LocalBrowserMenu, self).__setitem__(key, object)
return key
=== Zope3/src/zope/app/services/registration.py 1.14.4.6 => 1.14.4.7 ===
--- Zope3/src/zope/app/services/registration.py:1.14.4.6 Fri Sep 12 17:25:52 2003
+++ Zope3/src/zope/app/services/registration.py Mon Sep 15 14:12:38 2003
@@ -30,7 +30,8 @@
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, uncontained
+from zope.app.container.contained import Contained
+from zope.app.container.contained import setitem, contained, uncontained
from zope.exceptions import DuplicationError
class RegistrationStatusProperty(object):
@@ -570,6 +571,9 @@
return len(self._data)
def __setitem__(self, key, v):
+ setitem(self, self.__setitem, key, v)
+
+ def __setitem(self, key, v):
if key in self:
raise DuplicationError(key)
self._data += ((key, v), )
@@ -577,9 +581,7 @@
def addRegistration(self, object):
"See IWriteContainer"
key = self._chooseName('', object)
-
- object = contained(object, self, key)
- self._data += ((key, object), )
+ self[key] = object
return key
def _chooseName(self, name, object):
@@ -596,7 +598,7 @@
def __delitem__(self, key):
"See IWriteContainer"
- uncontained(self[key], self)
+ uncontained(self[key], self, key)
self._data = tuple(
[item
for item in self._data
=== Zope3/src/zope/app/services/service.py 1.29.18.2 => 1.29.18.3 ===
--- Zope3/src/zope/app/services/service.py:1.29.18.2 Fri Sep 12 15:15:33 2003
+++ Zope3/src/zope/app/services/service.py Mon Sep 15 14:12:38 2003
@@ -47,23 +47,27 @@
from zope.app.services.registration import NameComponentRegistry
from zope.app.services.registration import NamedComponentRegistration
-from zope.app.services.folder import SiteManagementFolders
+from zope.app.services.folder import SiteManagementFolder
from zope.app.interfaces.services.service import ILocalService
from zope.app.traversing import getPath
from zope.app.container.contained import Contained
+from zope.app.container.btree import BTreeContainer
-class ServiceManager(PersistentModuleRegistry, NameComponentRegistry,
- Contained):
-
- implements(IServiceManager, IContainer)
-
- def __init__(self):
+class ServiceManager(BTreeContainer,
+ PersistentModuleRegistry,
+ NameComponentRegistry,
+ ):
+
+ implements(IServiceManager)
+
+ def __init__(self, site):
+ self.__parent__ = site
+ self.__name__ = '++etc++site'
+ BTreeContainer.__init__(self)
PersistentModuleRegistry.__init__(self)
NameComponentRegistry.__init__(self)
- self.Packages = SiteManagementFolders(self)
- self.Packages.__parent__ = self
- self.Packages.__name__ = 'Packages'
+ self['default'] = SiteManagementFolder()
def getServiceDefinitions(wrapped_self):
"See IServiceService"
@@ -169,56 +173,6 @@
local += list(all)
return local
-
-
- # We provide a mapping interface for traversal, but we only expose
- # local services through the mapping interface.
-
- def __getitem__(self, key):
- "See Interface.Common.Mapping.IReadMapping"
-
- result = self.get(key)
- if result is None:
- raise KeyError(key)
-
- return result
-
- def get(wrapped_self, key, default=None):
- "See Interface.Common.Mapping.IReadMapping"
-
- if key == 'Packages':
- return wrapped_self.Packages
-
- return wrapped_self.Packages.get(key, default)
-
-
- def __contains__(self, key):
- "See Interface.Common.Mapping.IReadMapping"
-
- return self.get(key) is not None
-
- def __iter__(self):
- return iter(self.keys())
-
- def keys(self):
- return self.Packages.keys()
-
- def values(self):
- return map(self.get, self.keys())
-
-
- def items(self):
- return [(key, self.get(key)) for key in self.keys()]
-
-
- def __len__(self):
- return len(self.Packages)
-
- def __setitem__(self, name, value):
- self.Packages[name] = value
-
- def __delitem__(self, key):
- return self.Packages.__delitem__(key)
def findModule(wrapped_self, name):
# override to pass call up to next service manager
More information about the Zope3-Checkins
mailing list