Commit 324be297 authored by Hanno Schlichting's avatar Hanno Schlichting

OFS.ObjectManager now fully implements the zope.container.IContainer interface...

OFS.ObjectManager now fully implements the zope.container.IContainer interface and no longer just claims to do so. See the changelog for details and how backwards compatibility is handled.
parent 52e91401
......@@ -114,7 +114,24 @@ Restructuring
Features added
++++++++++++++
- Acquisition has been made aware of __parent__ pointers. This allows
- OFS.ObjectManager now fully implements the zope.container.IContainer
interface. For the last Zope2 releases it already claimed to implement the
interface, but didn't actually full-fill the interface contract. This means
you can start using more commonly used Python idioms to access objects inside
object managers. Complete dictionary-like access and container methods
including iteration are now supported. For each class derived from
ObjectManager you can use for any instance om: `om.keys()` instead of
`om.objectIds()`, `om.values()` instead of `om.objectValues()`, but also
`om.items()`, `ob.get('id')`, `ob['id']`, `'id' in om`, `iter(om)`,
`len(om)`, `om['id'] = object()` instead of `om._setObject('id', object())`
and `del ob['id']`. Should contained items of the object manager have ids
equal to any of the new method names, the objects will override the method,
as expected in Acquisition enabled types. Adding new objects into object
managers by those new names will no longer work, though. The added methods
call the already existing methods internally, so if a derived type overwrote
those, the new interface will provide the same functionality.
- Acquisition has been made aware of `__parent__` pointers. This allows
direct access to many Zope 3 classes without the need to mixin
Acquisition base classes for the security to work.
......
......@@ -54,7 +54,6 @@ from zope.event import notify
from zope.container.contained import ObjectAddedEvent
from zope.container.contained import ObjectRemovedEvent
from zope.container.contained import notifyContainerModified
from zope.container.interfaces import IContainer
from OFS.CopySupport import CopyContainer
from OFS.interfaces import IObjectManager
......@@ -156,7 +155,7 @@ class ObjectManager(CopyContainer,
# The claim to implement IContainer has been made during the Zope3
# integration project called Five but hasn't been completed in full.
implements(IObjectManager, IContainer)
implements(IObjectManager)
security = ClassSecurityInfo()
security.declareObjectProtected(access_contents_information)
......@@ -765,6 +764,9 @@ class ObjectManager(CopyContainer,
break
return marshal.dumps((mode,0,0,1,owner,group,0,mtime,mtime,mtime))
def __delitem__(self, name):
return self.manage_delObjects(ids=[name])
def __getitem__(self, key):
v=self._getOb(key, None)
if v is not None: return v
......@@ -775,6 +777,34 @@ class ObjectManager(CopyContainer,
return NullResource(self, key, request).__of__(self)
raise KeyError, key
def __setitem__(self, key, value):
return self._setObject(key, value)
def __contains__(self, name):
return name in self.objectIds()
def __iter__(self):
return iter(self.objectIds())
def __len__(self):
return len(self.objectIds())
security.declareProtected(access_contents_information, 'get')
def get(self, key, default=None):
return self._getOb(key, default)
security.declareProtected(access_contents_information, 'keys')
def keys(self):
return self.objectIds()
security.declareProtected(access_contents_information, 'get')
def items(self):
return self.objectItems()
security.declareProtected(access_contents_information, 'values')
def values(self):
return self.objectValues()
# Don't InitializeClass, there is a specific __class_init__ on ObjectManager
# InitializeClass(ObjectManager)
......
......@@ -14,6 +14,7 @@
$Id$
"""
from zope.container.interfaces import IContainer
from zope.interface import Attribute
from zope.interface import Interface
from zope.schema import Bool, BytesLine, Tuple
......@@ -474,7 +475,7 @@ class ICopyContainer(Interface):
# based on OFS.ObjectManager.ObjectManager
class IObjectManager(IZopeObject, ICopyContainer, INavigation, IManageable,
IAcquirer, IPersistent, IDAVCollection, ITraversable,
IPossibleSite):
IPossibleSite, IContainer):
"""Generic object manager
This interface provides core behavior for collections of heterogeneous
......@@ -582,10 +583,6 @@ class IObjectManager(IZopeObject, ICopyContainer, INavigation, IManageable,
"""
"""
def __getitem__(key):
"""
"""
# XXX: might contain non-API methods and outdated comments;
# not synced with ZopeBook API Reference;
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment