[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Content/Folder - Folder.py:1.1.4.5 FolderLimit.py:1.1.4.3 LoadedFolder.py:1.1.4.4 OrderedFolder.py:1.1.4.3
Jim Fulton
jim@zope.com
Mon, 10 Jun 2002 15:34:50 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Content/Folder
In directory cvs.zope.org:/tmp/cvs-serv5490/lib/python/Zope/App/OFS/Content/Folder
Modified Files:
Tag: Zope-3x-branch
Folder.py FolderLimit.py LoadedFolder.py OrderedFolder.py
Log Message:
Implemented
http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/IContainerPythonification
Along the way:
- Converted most uses of has_key to use in.
- Fixed a bug in Interface names and namesAndDescriptions methods
that caused base class attributes to be missed.
=== Zope3/lib/python/Zope/App/OFS/Content/Folder/Folder.py 1.1.4.4 => 1.1.4.5 ===
self.data = OOBTree()
- def objectIds(self):
+ def keys(self):
"""Return a sequence-like object containing the names
associated with the objects that appear in the folder
"""
return self.data.keys()
- def objectValues(self):
+ def __iter__(self):
+ return iter(self.data.keys())
+
+ def values(self):
"""Return a sequence-like object containing the objects that
appear in the folder.
"""
return self.data.values()
- def objectItems(self):
+ def items(self):
"""Return a sequence-like object containing tuples of the form
(name, object) for the objects that appear in the folder.
"""
return self.data.items()
- def getObject(self, name, default=KeyError):
+ def __getitem__(self, name):
+ """Return the named object, or the value of the default
+ argument if given and the named object is not found.
+ If no default is given and the object is not found a
+ KeyError is raised.
+ """
+ return self.data[name]
+
+ def get(self, name, default=None):
"""Return the named object, or the value of the default
argument if given and the named object is not found.
If no default is given and the object is not found a
KeyError is raised.
"""
- object = self.data.get(name, default)
- if object is KeyError:
- raise KeyError, name
- return object
+ return self.data.get(name, default)
- def hasObject(self, name):
+ def __contains__(self, name):
"""Return true if the named object appears in the folder."""
return self.data.has_key(name)
- def objectCount(self):
+ def __len__(self):
"""Return the number of objects in the folder."""
return len(self.data)
@@ -77,8 +85,9 @@
if type(name) in StringTypes and len(name)==0:
raise ValueError
self.data[name] = object
+ return name
- def delObject(self, name):
+ def __delitem__(self, name):
"""Delete the named object from the folder. Raises a KeyError
if the object is not found."""
del self.data[name]
=== Zope3/lib/python/Zope/App/OFS/Content/Folder/FolderLimit.py 1.1.4.2 => 1.1.4.3 ===
def isLimitReached(self):
'''See interface IContainerLimit'''
- if self.objectCount() >= self._limit:
+ if len(self) >= self._limit:
return 1
else:
return 0
=== Zope3/lib/python/Zope/App/OFS/Content/Folder/LoadedFolder.py 1.1.4.3 => 1.1.4.4 ===
# XXX Reimplementation of some of the IReadContainer API. Shrug.
- def objectIds(self):
+ def keys(self):
"""Return a sequence-like object containing the names
associated with the objects that appear in the folder
"""
return self._orderedIds
- def objectValues(self):
+ def values(self):
"""Return a sequence-like object containing the objects that
appear in the folder.
"""
result = []
- for id in self.objectIds():
+ for id in self.keys():
result.append(self.data[id])
return tuple(result)
- def objectItems(self):
+ def items(self):
"""Return a sequence-like object containing tuples of the form
(name, object) for the objects that appear in the folder.
"""
result = []
- for id in self.objectIds():
+ for id in self.keys():
result.append((id, self.data[id]))
return result
@@ -97,8 +97,9 @@
if name not in self._orderedIds:
self._orderedIds += (name,)
+ return name
- def delObject(self, name):
+ def __delitem__(self, name):
"""Delete the named object from the folder. Raises a KeyError
if the object is not found."""
del self.data[name]
=== Zope3/lib/python/Zope/App/OFS/Content/Folder/OrderedFolder.py 1.1.4.2 => 1.1.4.3 ===
# Make sure the new position makes sense and is valid
if not (old_position == new_position or
- new_position > self.objectCount() or
+ new_position > len(self) or
new_position < 0):
id_list = list(self._orderedIds)
@@ -110,8 +110,7 @@
ids = list(ids)
ids.reverse()
- position_delta = self.objectCount() - \
- self.getObjectPosition(ids[-1]) - 1
+ position_delta = len(self) - self.getObjectPosition(ids[-1]) - 1
return self.moveObjectsByPositions(ids, position_delta)