Added IList and IDict generic interfaces default
authortflorac
Mon, 12 Dec 2011 15:31:23 +0100
changeset 93 6f0fb6086bf3
parent 86 658842861161
child 102 824f49d5488e
child 103 088a873802df
Added IList and IDict generic interfaces
ztfy/utils/interfaces.py
--- a/ztfy/utils/interfaces.py	Mon Nov 07 13:02:19 2011 +0100
+++ b/ztfy/utils/interfaces.py	Mon Dec 12 15:31:23 2011 +0100
@@ -23,9 +23,120 @@
 # import local interfaces
 
 # import Zope3 packages
+from zope.interface import Interface
 
 # import local packages
 
 
 class INewSiteManagerEvent(IObjectEvent):
     """Event interface for new site manager event"""
+
+
+#
+# Generic list interface
+#
+
+class IListInfo(Interface):
+    """Custom interface used to handle list-like components"""
+
+    def count():
+        """Get list items count"""
+
+    def index():
+        """Get position of the given item"""
+
+    def __contains__():
+        """Check if given value is int list"""
+
+    def __getitem__():
+        """Return item at given position"""
+
+    def __iter__():
+        """Iterator over list items"""
+
+
+class IListWriter(Interface):
+    """Writer interface for list-like components"""
+
+    def append():
+        """Append value to list"""
+
+    def extend():
+        """Extend list with given items"""
+
+    def insert():
+        """Insert item to given index"""
+
+    def pop():
+        """Pop item from list and returns it"""
+
+    def remove():
+        """Remove given item from list"""
+
+    def reverse():
+        """Sort list in reverse order"""
+
+    def sort():
+        """Sort list"""
+
+
+class IList(IListInfo, IListWriter):
+    """Marker interface for list-like components"""
+
+
+#
+# Generic dict interface
+#
+
+class IDictInfo(Interface):
+    """Custom interface used to handle dict-like components"""
+
+    def keys():
+        """Get list of keys for the dict"""
+
+    def has_key(key):
+        """Check to know if dict includes the given key"""
+
+    def get(key, default=None):
+        """Get given key or default from dict"""
+
+    def copy():
+        """Duplicate content of dict"""
+
+    def __contains__(key):
+        """Check if given key is in dict"""
+
+    def __getitem__(key):
+        """Get given key value from dict"""
+
+    def __iter__():
+        """Iterator over dictionnary keys"""
+
+
+class IDictWriter(Interface):
+    """Writer interface for dict-like components"""
+
+    def clear():
+        """Clear dict"""
+
+    def update(b):
+        """Update dict with given values"""
+
+    def setdefault(key, failobj=None):
+        """Create value for given key if missing"""
+
+    def pop(key, *args):
+        """Remove and return given key from dict"""
+
+    def popitem():
+        """Pop item from dict"""
+
+    def __setitem__(key, value):
+        """Update given key with given value"""
+
+    def __delitem__(key):
+        """Remove selected key from dict"""
+
+
+class IDict(IDictInfo, IDictWriter):
+    """Marker interface for dict-like components"""