[Zope3-checkins] SVN: Zope3/trunk/src/zope/interface/common/mapping.py Specify more (all?) of the standard mapping interface, taking care not to

Gary Poster gary at zope.com
Tue Mar 1 10:45:04 EST 2005


Log message for revision 29359:
  Specify more (all?) of the standard mapping interface, taking care not to
  change the contracts of the already-defined interfaces.
  
  

Changed:
  U   Zope3/trunk/src/zope/interface/common/mapping.py

-=-
Modified: Zope3/trunk/src/zope/interface/common/mapping.py
===================================================================
--- Zope3/trunk/src/zope/interface/common/mapping.py	2005-03-01 14:48:27 UTC (rev 29358)
+++ Zope3/trunk/src/zope/interface/common/mapping.py	2005-03-01 15:45:04 UTC (rev 29359)
@@ -76,6 +76,52 @@
         """Return the number of items.
         """
 
+class IMapping(IWriteMapping, IEnumerableMapping):
+    ''' Simple mapping interface '''
 
-class IMapping(IReadMapping, IWriteMapping, IEnumerableMapping):
-    ''' Full mapping interface '''
+class IIterableMapping(IEnumerableMapping):
+
+    def iterkeys():
+        "iterate over keys; equivalent to __iter__"
+
+    def itervalues():
+        "iterate over values"
+
+    def iteritems():
+        "iterate over items"
+
+class IClonableMapping(Interface):
+    
+    def copy():
+        "return copy of dict"
+
+class IExtendedReadMapping(IIterableMapping):
+    
+    def has_key(key):
+        """Tell if a key exists in the mapping; equivalent to __contains__"""
+
+class IExtendedWriteMapping(IWriteMapping):
+    
+    def clear():
+        "delete all items"
+    
+    def update(d):
+        " Update D from E: for k in E.keys(): D[k] = E[k]"
+    
+    def setdefault(key, default=None):
+        "D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D"
+    
+    def pop(k, *args):
+        """remove specified key and return the corresponding value
+        *args may contain a single default value, or may not be supplied.
+        If key is not found, default is returned if given, otherwise 
+        KeyError is raised"""
+    
+    def popitem():
+        """remove and return some (key, value) pair as a
+        2-tuple; but raise KeyError if mapping is empty"""
+
+class IFullMapping(
+    IExtendedReadMapping, IExtendedWriteMapping, IClonableMapping, IMapping):
+    ''' Full mapping interface ''' # IMapping included so tests for IMapping
+    # succeed with IFullMapping



More information about the Zope3-Checkins mailing list