ztfy/utils/interfaces.py
changeset 93 6f0fb6086bf3
parent 50 3d97754e4181
equal deleted inserted replaced
86:658842861161 93:6f0fb6086bf3
    21 from zope.component.interfaces import IObjectEvent
    21 from zope.component.interfaces import IObjectEvent
    22 
    22 
    23 # import local interfaces
    23 # import local interfaces
    24 
    24 
    25 # import Zope3 packages
    25 # import Zope3 packages
       
    26 from zope.interface import Interface
    26 
    27 
    27 # import local packages
    28 # import local packages
    28 
    29 
    29 
    30 
    30 class INewSiteManagerEvent(IObjectEvent):
    31 class INewSiteManagerEvent(IObjectEvent):
    31     """Event interface for new site manager event"""
    32     """Event interface for new site manager event"""
       
    33 
       
    34 
       
    35 #
       
    36 # Generic list interface
       
    37 #
       
    38 
       
    39 class IListInfo(Interface):
       
    40     """Custom interface used to handle list-like components"""
       
    41 
       
    42     def count():
       
    43         """Get list items count"""
       
    44 
       
    45     def index():
       
    46         """Get position of the given item"""
       
    47 
       
    48     def __contains__():
       
    49         """Check if given value is int list"""
       
    50 
       
    51     def __getitem__():
       
    52         """Return item at given position"""
       
    53 
       
    54     def __iter__():
       
    55         """Iterator over list items"""
       
    56 
       
    57 
       
    58 class IListWriter(Interface):
       
    59     """Writer interface for list-like components"""
       
    60 
       
    61     def append():
       
    62         """Append value to list"""
       
    63 
       
    64     def extend():
       
    65         """Extend list with given items"""
       
    66 
       
    67     def insert():
       
    68         """Insert item to given index"""
       
    69 
       
    70     def pop():
       
    71         """Pop item from list and returns it"""
       
    72 
       
    73     def remove():
       
    74         """Remove given item from list"""
       
    75 
       
    76     def reverse():
       
    77         """Sort list in reverse order"""
       
    78 
       
    79     def sort():
       
    80         """Sort list"""
       
    81 
       
    82 
       
    83 class IList(IListInfo, IListWriter):
       
    84     """Marker interface for list-like components"""
       
    85 
       
    86 
       
    87 #
       
    88 # Generic dict interface
       
    89 #
       
    90 
       
    91 class IDictInfo(Interface):
       
    92     """Custom interface used to handle dict-like components"""
       
    93 
       
    94     def keys():
       
    95         """Get list of keys for the dict"""
       
    96 
       
    97     def has_key(key):
       
    98         """Check to know if dict includes the given key"""
       
    99 
       
   100     def get(key, default=None):
       
   101         """Get given key or default from dict"""
       
   102 
       
   103     def copy():
       
   104         """Duplicate content of dict"""
       
   105 
       
   106     def __contains__(key):
       
   107         """Check if given key is in dict"""
       
   108 
       
   109     def __getitem__(key):
       
   110         """Get given key value from dict"""
       
   111 
       
   112     def __iter__():
       
   113         """Iterator over dictionnary keys"""
       
   114 
       
   115 
       
   116 class IDictWriter(Interface):
       
   117     """Writer interface for dict-like components"""
       
   118 
       
   119     def clear():
       
   120         """Clear dict"""
       
   121 
       
   122     def update(b):
       
   123         """Update dict with given values"""
       
   124 
       
   125     def setdefault(key, failobj=None):
       
   126         """Create value for given key if missing"""
       
   127 
       
   128     def pop(key, *args):
       
   129         """Remove and return given key from dict"""
       
   130 
       
   131     def popitem():
       
   132         """Pop item from dict"""
       
   133 
       
   134     def __setitem__(key, value):
       
   135         """Update given key with given value"""
       
   136 
       
   137     def __delitem__(key):
       
   138         """Remove selected key from dict"""
       
   139 
       
   140 
       
   141 class IDict(IDictInfo, IDictWriter):
       
   142     """Marker interface for dict-like components"""