[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/ Removed unnecessary subscriber for GroupChangedEvent.

Amos Brocco amos.brocco at mriyasoftware.com
Thu Oct 14 08:22:16 EDT 2004


Log message for revision 28166:
  Removed unnecessary subscriber for GroupChangedEvent.
  
  Renamed ISearchPlugin.get() method to ISearchPlugin.principalInfo()
  
  Updated implementations and tests.
  

Changed:
  U   Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.py
  U   Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.txt
  U   Zope3/trunk/src/zope/app/pas/interfaces.py

-=-
Modified: Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.py
===================================================================
--- Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.py	2004-10-14 12:18:53 UTC (rev 28165)
+++ Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.py	2004-10-14 12:22:14 UTC (rev 28166)
@@ -37,11 +37,12 @@
         self.__inverseMapping = OOBTree()
 
     def __delitem__(self, name):
-        """ Removes a group and updates the inverse mapping"""
+        """Removes a group and updates the inverse mapping"""
         for principal in self.__inverseMapping.keys():
             groupListForPrincipal = self.__inverseMapping[principal]
             if name in groupListForPrincipal:
                 groupListForPrincipal.remove(name)
+        # Clean up 
         for principal in self.__inverseMapping.keys():
             groupListForPrincipal = self.__inverseMapping[principal]
             if len(groupListForPrincipal) == 0:
@@ -56,12 +57,11 @@
             if self.__inverseMapping.has_key(principal):
                 self.__inverseMapping[principal].append(name)
             else:
-                self.__inverseMapping[principal] = [name]
-                     
+                self.__inverseMapping[principal] = [name]        
    
     def getGroupsForPrincipal(self, principalid):
         """Get groups the given principal belongs to"""
-        if principalid in self.__inverseMapping.keys():
+        if self.__inverseMapping.has_key(principalid):
             return self.__inverseMapping[principalid]
         else:
             return []
@@ -104,7 +104,6 @@
     def search(self, query, start=None, batch_size=None):
         """ Search for groups"""
         search = query.get('search')
-        tmpResults = []
         if search is not None:
             i = 0
             n = 0
@@ -113,7 +112,13 @@
                     if not ((start is not None and i < start)
                             or
                             (batch_size is not None and n > batch_size)):
-                        tmpResults.append(value)
-        return tmpResults
+                        n += 1
+                        yield value
+                i += 1
         
+    def principalInfo(self, id):
+        if id in self:
+            return {'title': self[id].title, 'description': self[id].description}
+        
+        
             

Modified: Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.txt
===================================================================
--- Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.txt	2004-10-14 12:18:53 UTC (rev 28165)
+++ Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.txt	2004-10-14 12:22:14 UTC (rev 28166)
@@ -1,5 +1,5 @@
 Groups Folder Implementation
-========================
+============================
 
 The GroupsFolder class offers a groups container that mantains maps between groups and principals as 
 well as maps from principals to groups.
@@ -10,25 +10,25 @@
 a principal belongs to by providing its id.
    
       >>> import zope.interface
-      >>> from zope.security.interfaces import IPrincipal, IGroup
+      >>> from zope.security.interfaces import IGroupAwarePrincipal, IGroup
       >>> from zope.security.group import Group
       >>> from zope.app.groupscontainer.interfaces import IGroupsFolder, IGroupContained
       >>> from zope.app.groupscontainer.groupsfolder import GroupsFolder
       >>> from zope.interface import implements
       >>> class GoldrakePrincipal:
-      ...     implements(IPrincipal)
+      ...     implements(IGroupAwarePrincipal)
       ...     id = '0'
       ...     title = 'Goldrake'
       ...     description = 'Ufo robot'
       ...     groups = ['superheroes', 'robots']
       >>> class MazingaPrincipal:
-      ...     implements(IPrincipal)
+      ...     implements(IGroupAwarePrincipal)
       ...     id = '1'
       ...     title = 'Mazinga'
       ...     description = 'Mazinga Z'
       ...     groups = ['superheroes', 'robots']
       >>> class CaptainAmericaPrincipal:
-      ...     implements(IPrincipal)
+      ...     implements(IGroupAwarePrincipal)
       ...     id = '2'
       ...     title = 'CaptainAmerica'
       ...     description = 'Captain America'
@@ -71,8 +71,12 @@
       [u'robots']
       >>> notordinarypeople.getGroupsForPrincipal('1')
       ['robots']
+      >>> mazinga.groups
+      ['superheroes', 'robots']
       >>> notordinarypeople.getGroupsForPrincipal('2')
       []
+      >>> captainamerica.groups
+      ['superheroes']
       
     Now we test the search capabilities, as in IQuerySchemaSearch example:
     
@@ -117,7 +121,7 @@
     
     so that we now get results (!):
     
-      >>> view.results('test')
+      >>> list(view.results('test'))
       [u'robots']
       >>> request.form['test.field.search'] = 'eek'
       

Modified: Zope3/trunk/src/zope/app/pas/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/pas/interfaces.py	2004-10-14 12:18:53 UTC (rev 28165)
+++ Zope3/trunk/src/zope/app/pas/interfaces.py	2004-10-14 12:22:14 UTC (rev 28166)
@@ -176,7 +176,7 @@
         (See README.txt.)
     """
 
-    def get(principal_id):
+    def principalInfo(principal_id):
         """Try to get principal information for the principal id.
 
         If the principal id is valid, then return a dictionary



More information about the Zope3-Checkins mailing list