[CalendarServer-changes] [10661] CalendarServer/trunk/twext/who/idirectory.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Feb 7 17:23:03 PST 2013


Revision: 10661
          http://trac.calendarserver.org//changeset/10661
Author:   wsanchez at apple.com
Date:     2013-02-07 17:23:03 -0800 (Thu, 07 Feb 2013)
Log Message:
-----------
Add __repr__ to DirectoryQueryMatchExpression.
Get rid of _DescriptionMixIn, which doesn't work.

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

Modified: CalendarServer/trunk/twext/who/idirectory.py
===================================================================
--- CalendarServer/trunk/twext/who/idirectory.py	2013-02-08 01:05:55 UTC (rev 10660)
+++ CalendarServer/trunk/twext/who/idirectory.py	2013-02-08 01:23:03 UTC (rev 10661)
@@ -64,18 +64,16 @@
 # Data Types
 ##
 
-class _DescriptionMixIn(object):
-    def __str__(self):
-        return getattr(self, "description", Names.__str__(self))
-
-class RecordType(Names, _DescriptionMixIn):
+class RecordType(Names):
     user  = NamedConstant()
     group = NamedConstant()
 
     user.description  = "user"
     group.description = "group"
 
-class FieldName(Names, _DescriptionMixIn):
+
+
+class FieldName(Names):
     """
     Constants for common field names.
     """
@@ -103,7 +101,9 @@
     def isMultiValue(name):
         return getattr(name, "multiValue", False)
 
-class MatchType(Names, _DescriptionMixIn):
+
+
+class MatchType(Names):
     """
     Query match types.
     """
@@ -115,14 +115,18 @@
     startsWith.description = "starts with"
     contains.description   = "contains"
 
-class Operand(Names, _DescriptionMixIn):
+
+
+class Operand(Names):
     OR  = NamedConstant()
     AND = NamedConstant()
 
     OR.description  = "or"
     AND.description = "and"
 
-class QueryFlags(Flags, _DescriptionMixIn):
+
+
+class QueryFlags(Flags):
     """
     Query flags.
     """
@@ -130,6 +134,8 @@
 
     caseInsensitive.description = "case insensitive"
 
+
+
 class DirectoryQueryMatchExpression(object):
     """
     Query for a matching value in a given field.
@@ -146,8 +152,28 @@
         self.matchType  = matchType
         self.flags      = flags
 
+    def __repr__(self):
+        def describe(constant):
+            if hasattr(constant, "description"):
+                return constant.description
+            else:
+                return str(constant)
 
+        if self.flags is None:
+            flags = ""
+        else:
+            flags = " (%s)" % (self.flags,)
 
+        return "<%s: %r %s %r%s>" % (
+            self.__class__.__name__,
+            describe(self.fieldName),
+            describe(self.matchType),
+            describe(self.fieldValue),
+            flags
+        )
+
+
+
 ##
 # Interfaces
 ##
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130207/11ba4844/attachment.html>


More information about the calendarserver-changes mailing list