[CalendarServer-changes] [13288] twext/trunk/twext/who/opendirectory/_service.py

source_changes at macosforge.org source_changes at macosforge.org
Tue Apr 15 14:50:44 PDT 2014


Revision: 13288
          http://trac.calendarserver.org//changeset/13288
Author:   wsanchez at apple.com
Date:     2014-04-15 14:50:44 -0700 (Tue, 15 Apr 2014)
Log Message:
-----------
More cleanup

Modified Paths:
--------------
    twext/trunk/twext/who/opendirectory/_service.py

Modified: twext/trunk/twext/who/opendirectory/_service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/_service.py	2014-04-15 21:36:36 UTC (rev 13287)
+++ twext/trunk/twext/who/opendirectory/_service.py	2014-04-15 21:50:44 UTC (rev 13288)
@@ -211,7 +211,7 @@
             self._node = node
 
 
-    def _queryStringAndRecordTypeFromMatchExpression(self, expression):
+    def _queryStringFromMatchExpression(self, expression):
         """
         Generates an OD query string from a match expression.
 
@@ -280,7 +280,7 @@
         @rtype: (C{unicode}, set(C{unicode}))
         """
         if recordTypes is None:
-            recordTypes = set([t.value for t in ODRecordType.iterconstants()])
+            recordTypes = set(ODRecordType.iterconstants())
 
         queryTokens = []
         for subExpression in expression.expressions:
@@ -319,7 +319,7 @@
         return (u"".join(queryTokens), recordTypes)
 
 
-    def _queryStringFromExpression(self, expression, recordTypes=set(ODRecordType.iterconstants())):
+    def _queryStringFromExpression(self, expression, recordTypes=None):
         """
         Converts either a MatchExpression or a CompoundExpression into an LDAP
         query string.
@@ -335,10 +335,9 @@
         """
 
         if isinstance(expression, MatchExpression):
-            queryString, recordType = self._queryStringAndRecordTypeFromMatchExpression(
+            return self._queryStringFromMatchExpression(
                 expression
             )
-            return (queryString, recordType if recordType else recordTypes)
 
         if isinstance(expression, CompoundExpression):
             return self._queryStringFromCompoundExpression(
@@ -431,11 +430,9 @@
                     "recordType argument does not match expression"
                 )
 
-            recordTypes = ODRecordType.fromRecordType(
-                expression.fieldValue
-            ).value
+            recordTypes = ODRecordType.fromRecordType(expression.fieldValue)
             if MatchFlags.NOT in flags:
-                recordTypes = set([t.value for t in ODRecordType.iterconstants()]) - recordTypes
+                recordTypes = None
 
             matchType = ODMatchType.any.value
             queryAttribute = None
@@ -446,9 +443,9 @@
                 raise NotImplementedError()
 
             if recordType is None:
-                recordTypes = [t.value for t in ODRecordType.iterconstants()]
+                recordTypes = None
             else:
-                recordTypes = ODRecordType.fromRecordType(recordType).value
+                recordTypes = (ODRecordType.fromRecordType(recordType),)
 
             queryAttribute = ODAttribute.fromFieldName(
                 expression.fieldName
@@ -483,10 +480,25 @@
     def _buildQuery(
         self, recordTypes, matchType, queryString, queryAttribute=None
     ):
+        if not hasattr(self, "_odQuery"):
+            self._odQuery = getattr(
+                ODQuery,
+                "queryWithNode_"
+                "forRecordTypes_"
+                "attribute_"
+                "matchType_"
+                "queryValues_"
+                "returnAttributes_"
+                "maximumResults_error_"
+            )
+
         if not hasattr(self, "_odAttributes"):
             self._odAttributes = [a.value for a in ODAttribute.iterconstants()]
 
-        return ODQuery.queryWithNode_forRecordTypes_attribute_matchType_queryValues_returnAttributes_maximumResults_error_(
+        if recordTypes is None:
+            recordTypes = ODRecordType.itervalues()
+
+        return self._odQuery(
             self.node,                       # node
             (t.value for t in recordTypes),  # record types
             queryAttribute,                  # attribute
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140415/94f41d7c/attachment-0001.html>


More information about the calendarserver-changes mailing list