[CalendarServer-changes] [435] CalendarServer/branches/users/wsanchez/provisioning/twistedcaldav/ directory

source_changes at macosforge.org source_changes at macosforge.org
Fri Nov 10 17:11:22 PST 2006


Revision: 435
          http://trac.macosforge.org/projects/calendarserver/changeset/435
Author:   wsanchez at apple.com
Date:     2006-11-10 17:11:22 -0800 (Fri, 10 Nov 2006)

Log Message:
-----------
Add __cmp__ and __hash__ to directory objects.

Modified Paths:
--------------
    CalendarServer/branches/users/wsanchez/provisioning/twistedcaldav/directory/appleopendirectory.py
    CalendarServer/branches/users/wsanchez/provisioning/twistedcaldav/directory/directory.py

Modified: CalendarServer/branches/users/wsanchez/provisioning/twistedcaldav/directory/appleopendirectory.py
===================================================================
--- CalendarServer/branches/users/wsanchez/provisioning/twistedcaldav/directory/appleopendirectory.py	2006-11-11 00:57:53 UTC (rev 434)
+++ CalendarServer/branches/users/wsanchez/provisioning/twistedcaldav/directory/appleopendirectory.py	2006-11-11 01:11:22 UTC (rev 435)
@@ -26,6 +26,8 @@
     "OpenDirectoryInitError",
 ]
 
+import sys
+
 import opendirectory
 import dsattributes
 
@@ -52,13 +54,29 @@
 
         self.directory = directory
         self.node = node
-        self.records = {}
+        self._records = {}
 
+    def __cmp__(self, other):
+        if not isinstance(other, DirectoryRecord):
+            return super(DirectoryRecord, self).__eq__(other)
+
+        for attr in ("directory", "node"):
+            diff = cmp(getattr(self, attr), getattr(other, attr))
+            if diff != 0:
+                return diff
+        return 0
+
+    def __hash__(self):
+        h = hash(self.__class__)
+        for attr in ("directory", "node"):
+            h = (h + hash(getattr(self, attr))) & sys.maxint
+        return h
+
     def recordTypes(self):
         return ("user", "group", "resource")
 
     def _cacheRecords(self, recordType):
-        if recordType not in self.records:
+        if recordType not in self._records:
             log.msg("Reloading %s record cache" % (recordType,))
 
             if recordType == "user":
@@ -83,18 +101,18 @@
                     )
 
             if records:
-                self.records[recordType] = records
+                self._records[recordType] = records
 
                 def flush():
                     log.msg("Flushing %s record cache" % (recordType,))
-                    del self.records[recordType]
+                    del self._records[recordType]
                 reactor.callLater(recordListCacheTimeout, flush)
             else:
                 # records is empty.  This may mean the directory went down.
                 # Don't cache this result, so that we keep checking the directory.
                 return records
 
-        return self.records[recordType]
+        return self._records[recordType]
 
     def listRecords(self, recordType):
         return self._cacheRecords(recordType).values()
@@ -147,13 +165,11 @@
 
         # FIXME:
         # Need an API here from opendirectory which finds all members of a group
-
         raise NotImplementedError("OpenDirectoryRecord.members() for groups")
 
     def groups(self):
         # FIXME:
         # Need an API here from opendirectory which finds all groups containing this member
-
         raise NotImplementedError("OpenDirectoryRecord.groups()")
 
     def verifyCredentials(self, credentials):

Modified: CalendarServer/branches/users/wsanchez/provisioning/twistedcaldav/directory/directory.py
===================================================================
--- CalendarServer/branches/users/wsanchez/provisioning/twistedcaldav/directory/directory.py	2006-11-11 00:57:53 UTC (rev 434)
+++ CalendarServer/branches/users/wsanchez/provisioning/twistedcaldav/directory/directory.py	2006-11-11 01:11:22 UTC (rev 435)
@@ -28,6 +28,8 @@
     "UnknownRecordTypeError",
 ]
 
+import sys
+
 from zope.interface import implements
 
 from twistedcaldav.directory.idirectory import IDirectoryService, IDirectoryRecord
@@ -48,6 +50,22 @@
         self.shortName  = shortName
         self.fullName   = fullName
 
+    def __cmp__(self, other):
+        if not isinstance(other, DirectoryRecord):
+            return super(DirectoryRecord, self).__eq__(other)
+
+        for attr in ("service", "recordType", "shortName", "guid"):
+            diff = cmp(getattr(self, attr), getattr(other, attr))
+            if diff != 0:
+                return diff
+        return 0
+
+    def __hash__(self):
+        h = hash(self.__class__)
+        for attr in ("service", "recordType", "shortName", "guid"):
+            h = (h + hash(getattr(self, attr))) & sys.maxint
+        return h
+
     def members(self):
         return ()
 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20061110/6878a8ee/attachment.html


More information about the calendarserver-changes mailing list