[CalendarServer-changes] [10723] CalendarServer/trunk/twext/who/directory.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Feb 13 18:42:28 PST 2013


Revision: 10723
          http://trac.calendarserver.org//changeset/10723
Author:   wsanchez at apple.com
Date:     2013-02-13 18:42:28 -0800 (Wed, 13 Feb 2013)
Log Message:
-----------
Change __eq__ to reply on interfaces.

Modified Paths:
--------------
    CalendarServer/trunk/twext/who/directory.py

Modified: CalendarServer/trunk/twext/who/directory.py
===================================================================
--- CalendarServer/trunk/twext/who/directory.py	2013-02-14 01:51:26 UTC (rev 10722)
+++ CalendarServer/trunk/twext/who/directory.py	2013-02-14 02:42:28 UTC (rev 10723)
@@ -27,7 +27,6 @@
 
 from zope.interface import implements
 
-from twisted.python.util import FancyEqMixin
 from twisted.internet.defer import inlineCallbacks, returnValue
 from twisted.internet.defer import succeed, fail
 
@@ -40,13 +39,9 @@
 
 
 
-class DirectoryService(FancyEqMixin, object):
+class DirectoryService(object):
     implements(IDirectoryService)
 
-    compareAttributes = (
-        "realmName",
-    )
-
     recordType = RecordType
     fieldName  = FieldName
 
@@ -67,6 +62,19 @@
         )
 
 
+    def __eq__(self, other):
+        if IDirectoryService.implementedBy(other.__class__):
+            return self.realmName == other.realmName
+        return NotImplemented
+
+
+    def __ne__(self, other):
+        eq = self.__eq__(other)
+        if eq is NotImplemented:
+            return NotImplemented
+        return not eq
+
+
     def recordTypes(self):
         return succeed(self.recordType.iterconstants())
 
@@ -142,7 +150,7 @@
 
 
 
-class DirectoryRecord(FancyEqMixin, object):
+class DirectoryRecord(object):
     implements(IDirectoryRecord)
 
     requiredFields = (
@@ -200,7 +208,7 @@
 
 
     def __eq__(self, other):
-        if isinstance(self, other.__class__):
+        if IDirectoryRecord.implementedBy(other.__class__):
             return (
                 self.service == other.service and
                 self.fields[FieldName.uid] == other.fields[FieldName.uid]
@@ -208,6 +216,13 @@
         return NotImplemented
 
 
+    def __ne__(self, other):
+        eq = self.__eq__(other)
+        if eq is NotImplemented:
+            return NotImplemented
+        return not eq
+
+
     def __getattr__(self, name):
         try:
             fieldName = self.service.fieldName.lookupByName(name)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130213/4144615d/attachment.html>


More information about the calendarserver-changes mailing list