[CalendarServer-changes] [13660] twext/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Jun 18 14:13:47 PDT 2014


Revision: 13660
          http://trac.calendarserver.org//changeset/13660
Author:   sagen at apple.com
Date:     2014-06-18 14:13:47 -0700 (Wed, 18 Jun 2014)
Log Message:
-----------
Land recordtypes branch

Modified Paths:
--------------
    twext/trunk/twext/who/aggregate.py
    twext/trunk/twext/who/directory.py
    twext/trunk/twext/who/idirectory.py
    twext/trunk/twext/who/index.py
    twext/trunk/twext/who/ldap/_service.py
    twext/trunk/twext/who/opendirectory/_service.py
    twext/trunk/twext/who/test/test_directory.py
    twext/trunk/twext/who/test/test_index.py
    twext/trunk/twext/who/test/test_xml.py

Property Changed:
----------------
    twext/trunk/
    twext/trunk/twext/


Property changes on: twext/trunk
___________________________________________________________________
Modified: svn:mergeinfo
   - /twext/branches/users/cdaboo/jobqueue-3:13444-13471
/twext/branches/users/cdaboo/jobs:12742-12780
   + /twext/branches/users/cdaboo/jobqueue-3:13444-13471
/twext/branches/users/cdaboo/jobs:12742-12780
/twext/branches/users/sagen/recordtypes:13647-13658
/twext/branches/users/sagen/recordtypes-2:13659


Property changes on: twext/trunk/twext
___________________________________________________________________
Modified: svn:mergeinfo
   - /CalDAVTester/trunk/twext:11193-11198
/CalendarServer/branches/config-separation/twext:4379-4443
/CalendarServer/branches/egg-info-351/twext:4589-4625
/CalendarServer/branches/generic-sqlstore/twext:6167-6191
/CalendarServer/branches/new-store-no-caldavfile-2/twext:5936-5981
/CalendarServer/branches/new-store-no-caldavfile/twext:5911-5935
/CalendarServer/branches/new-store/twext:5594-5934
/CalendarServer/branches/release/CalendarServer-4.3-dev/twext:10180-10190,10192
/CalendarServer/branches/release/CalendarServer-5.1-dev/twext:11846
/CalendarServer/branches/users/cdaboo/batchupload-6699/twext:6700-7198
/CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692/twext:5693-5702
/CalendarServer/branches/users/cdaboo/component-set-fixes/twext:8130-8346
/CalendarServer/branches/users/cdaboo/directory-cache-on-demand-3627/twext:3628-3644
/CalendarServer/branches/users/cdaboo/fix-no-ischedule/twext:11607-11871
/CalendarServer/branches/users/cdaboo/implicituidrace/twext:8137-8141
/CalendarServer/branches/users/cdaboo/ischedule-dkim/twext:9747-9979
/CalendarServer/branches/users/cdaboo/json/twext:11622-11912
/CalendarServer/branches/users/cdaboo/managed-attachments/twext:9985-10145
/CalendarServer/branches/users/cdaboo/more-sharing-5591/twext:5592-5601
/CalendarServer/branches/users/cdaboo/partition-4464/twext:4465-4957
/CalendarServer/branches/users/cdaboo/performance-tweaks/twext:11824-11836
/CalendarServer/branches/users/cdaboo/pods/twext:7297-7377
/CalendarServer/branches/users/cdaboo/pycalendar/twext:7085-7206
/CalendarServer/branches/users/cdaboo/pycard/twext:7227-7237
/CalendarServer/branches/users/cdaboo/queued-attendee-refreshes/twext:7740-8287
/CalendarServer/branches/users/cdaboo/relative-config-paths-5070/twext:5071-5105
/CalendarServer/branches/users/cdaboo/reverse-proxy-pods/twext:11875-11900
/CalendarServer/branches/users/cdaboo/shared-calendars-5187/twext:5188-5440
/CalendarServer/branches/users/cdaboo/sharing-in-the-store/twext:11935-12016
/CalendarServer/branches/users/cdaboo/store-scheduling/twext:10876-11129
/CalendarServer/branches/users/cdaboo/timezones/twext:7443-7699
/CalendarServer/branches/users/cdaboo/txn-debugging/twext:8730-8743
/CalendarServer/branches/users/gaya/sharedgroups-3/twext:11088-11204
/CalendarServer/branches/users/glyph/always-abort-txn-on-error/twext:9958-9969
/CalendarServer/branches/users/glyph/case-insensitive-uid/twext:8772-8805
/CalendarServer/branches/users/glyph/conn-limit/twext:6574-6577
/CalendarServer/branches/users/glyph/contacts-server-merge/twext:4971-5080
/CalendarServer/branches/users/glyph/dalify/twext:6932-7023
/CalendarServer/branches/users/glyph/db-reconnect/twext:6824-6876
/CalendarServer/branches/users/glyph/deploybuild/twext:7563-7572
/CalendarServer/branches/users/glyph/digest-auth-redux/twext:10624-10635
/CalendarServer/branches/users/glyph/disable-quota/twext:7718-7727
/CalendarServer/branches/users/glyph/dont-start-postgres/twext:6592-6614
/CalendarServer/branches/users/glyph/enforce-max-requests/twext:11640-11643
/CalendarServer/branches/users/glyph/hang-fix/twext:11465-11491
/CalendarServer/branches/users/glyph/imip-and-admin-html/twext:7866-7984
/CalendarServer/branches/users/glyph/ipv6-client/twext:9054-9105
/CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext:11413-11436
/CalendarServer/branches/users/glyph/linux-tests/twext:6893-6900
/CalendarServer/branches/users/glyph/log-cleanups/twext:11691-11731
/CalendarServer/branches/users/glyph/migrate-merge/twext:8690-8713
/CalendarServer/branches/users/glyph/misc-portability-fixes/twext:7365-7374
/CalendarServer/branches/users/glyph/more-deferreds-6/twext:6322-6368
/CalendarServer/branches/users/glyph/more-deferreds-7/twext:6369-6445
/CalendarServer/branches/users/glyph/multiget-delete/twext:8321-8330
/CalendarServer/branches/users/glyph/new-export/twext:7444-7485
/CalendarServer/branches/users/glyph/one-home-list-api/twext:10048-10073
/CalendarServer/branches/users/glyph/oracle-nulls/twext:7340-7351
/CalendarServer/branches/users/glyph/oracle/twext:7106-7155
/CalendarServer/branches/users/glyph/other-html/twext:8062-8091
/CalendarServer/branches/users/glyph/parallel-sim/twext:8240-8251
/CalendarServer/branches/users/glyph/parallel-upgrade/twext:8376-8400
/CalendarServer/branches/users/glyph/parallel-upgrade_to_1/twext:8571-8583
/CalendarServer/branches/users/glyph/q/twext:9560-9688
/CalendarServer/branches/users/glyph/queue-locking-and-timing/twext:10204-10289
/CalendarServer/branches/users/glyph/quota/twext:7604-7637
/CalendarServer/branches/users/glyph/sendfdport/twext:5388-5424
/CalendarServer/branches/users/glyph/shared-pool-fixes/twext:8436-8443
/CalendarServer/branches/users/glyph/shared-pool-take2/twext:8155-8174
/CalendarServer/branches/users/glyph/sharedpool/twext:6490-6550
/CalendarServer/branches/users/glyph/sharing-api/twext:9192-9205
/CalendarServer/branches/users/glyph/skip-lonely-vtimezones/twext:8524-8535
/CalendarServer/branches/users/glyph/sql-store/twext:5929-6073
/CalendarServer/branches/users/glyph/start-service-start-loop/twext:11060-11065
/CalendarServer/branches/users/glyph/subtransactions/twext:7248-7258
/CalendarServer/branches/users/glyph/table-alias/twext:8651-8664
/CalendarServer/branches/users/glyph/uidexport/twext:7673-7676
/CalendarServer/branches/users/glyph/unshare-when-access-revoked/twext:10562-10595
/CalendarServer/branches/users/glyph/use-system-twisted/twext:5084-5149
/CalendarServer/branches/users/glyph/uuid-normalize/twext:9268-9296
/CalendarServer/branches/users/glyph/warning-cleanups/twext:11347-11357
/CalendarServer/branches/users/glyph/whenNotProposed/twext:11881-11897
/CalendarServer/branches/users/glyph/xattrs-from-files/twext:7757-7769
/CalendarServer/branches/users/sagen/applepush/twext:8126-8184
/CalendarServer/branches/users/sagen/inboxitems/twext:7380-7381
/CalendarServer/branches/users/sagen/locations-resources-2/twext:5052-5061
/CalendarServer/branches/users/sagen/locations-resources/twext:5032-5051
/CalendarServer/branches/users/sagen/purge_old_events/twext:6735-6746
/CalendarServer/branches/users/sagen/resource-delegates-4038/twext:4040-4067
/CalendarServer/branches/users/sagen/resource-delegates-4066/twext:4068-4075
/CalendarServer/branches/users/sagen/resources-2/twext:5084-5093
/CalendarServer/branches/users/sagen/testing/twext:10827-10851,10853-10855
/CalendarServer/branches/users/wsanchez/transations/twext:5515-5593
/twext/branches/users/cdaboo/jobqueue-3/twext:13444-13471
/twext/branches/users/cdaboo/jobs/twext:12742-12780
   + /CalDAVTester/trunk/twext:11193-11198
/CalendarServer/branches/config-separation/twext:4379-4443
/CalendarServer/branches/egg-info-351/twext:4589-4625
/CalendarServer/branches/generic-sqlstore/twext:6167-6191
/CalendarServer/branches/new-store/twext:5594-5934
/CalendarServer/branches/new-store-no-caldavfile/twext:5911-5935
/CalendarServer/branches/new-store-no-caldavfile-2/twext:5936-5981
/CalendarServer/branches/release/CalendarServer-4.3-dev/twext:10180-10190,10192
/CalendarServer/branches/release/CalendarServer-5.1-dev/twext:11846
/CalendarServer/branches/users/cdaboo/batchupload-6699/twext:6700-7198
/CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692/twext:5693-5702
/CalendarServer/branches/users/cdaboo/component-set-fixes/twext:8130-8346
/CalendarServer/branches/users/cdaboo/directory-cache-on-demand-3627/twext:3628-3644
/CalendarServer/branches/users/cdaboo/fix-no-ischedule/twext:11607-11871
/CalendarServer/branches/users/cdaboo/implicituidrace/twext:8137-8141
/CalendarServer/branches/users/cdaboo/ischedule-dkim/twext:9747-9979
/CalendarServer/branches/users/cdaboo/json/twext:11622-11912
/CalendarServer/branches/users/cdaboo/managed-attachments/twext:9985-10145
/CalendarServer/branches/users/cdaboo/more-sharing-5591/twext:5592-5601
/CalendarServer/branches/users/cdaboo/partition-4464/twext:4465-4957
/CalendarServer/branches/users/cdaboo/performance-tweaks/twext:11824-11836
/CalendarServer/branches/users/cdaboo/pods/twext:7297-7377
/CalendarServer/branches/users/cdaboo/pycalendar/twext:7085-7206
/CalendarServer/branches/users/cdaboo/pycard/twext:7227-7237
/CalendarServer/branches/users/cdaboo/queued-attendee-refreshes/twext:7740-8287
/CalendarServer/branches/users/cdaboo/relative-config-paths-5070/twext:5071-5105
/CalendarServer/branches/users/cdaboo/reverse-proxy-pods/twext:11875-11900
/CalendarServer/branches/users/cdaboo/shared-calendars-5187/twext:5188-5440
/CalendarServer/branches/users/cdaboo/sharing-in-the-store/twext:11935-12016
/CalendarServer/branches/users/cdaboo/store-scheduling/twext:10876-11129
/CalendarServer/branches/users/cdaboo/timezones/twext:7443-7699
/CalendarServer/branches/users/cdaboo/txn-debugging/twext:8730-8743
/CalendarServer/branches/users/gaya/sharedgroups-3/twext:11088-11204
/CalendarServer/branches/users/glyph/always-abort-txn-on-error/twext:9958-9969
/CalendarServer/branches/users/glyph/case-insensitive-uid/twext:8772-8805
/CalendarServer/branches/users/glyph/conn-limit/twext:6574-6577
/CalendarServer/branches/users/glyph/contacts-server-merge/twext:4971-5080
/CalendarServer/branches/users/glyph/dalify/twext:6932-7023
/CalendarServer/branches/users/glyph/db-reconnect/twext:6824-6876
/CalendarServer/branches/users/glyph/deploybuild/twext:7563-7572
/CalendarServer/branches/users/glyph/digest-auth-redux/twext:10624-10635
/CalendarServer/branches/users/glyph/disable-quota/twext:7718-7727
/CalendarServer/branches/users/glyph/dont-start-postgres/twext:6592-6614
/CalendarServer/branches/users/glyph/enforce-max-requests/twext:11640-11643
/CalendarServer/branches/users/glyph/hang-fix/twext:11465-11491
/CalendarServer/branches/users/glyph/imip-and-admin-html/twext:7866-7984
/CalendarServer/branches/users/glyph/ipv6-client/twext:9054-9105
/CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext:11413-11436
/CalendarServer/branches/users/glyph/linux-tests/twext:6893-6900
/CalendarServer/branches/users/glyph/log-cleanups/twext:11691-11731
/CalendarServer/branches/users/glyph/migrate-merge/twext:8690-8713
/CalendarServer/branches/users/glyph/misc-portability-fixes/twext:7365-7374
/CalendarServer/branches/users/glyph/more-deferreds-6/twext:6322-6368
/CalendarServer/branches/users/glyph/more-deferreds-7/twext:6369-6445
/CalendarServer/branches/users/glyph/multiget-delete/twext:8321-8330
/CalendarServer/branches/users/glyph/new-export/twext:7444-7485
/CalendarServer/branches/users/glyph/one-home-list-api/twext:10048-10073
/CalendarServer/branches/users/glyph/oracle/twext:7106-7155
/CalendarServer/branches/users/glyph/oracle-nulls/twext:7340-7351
/CalendarServer/branches/users/glyph/other-html/twext:8062-8091
/CalendarServer/branches/users/glyph/parallel-sim/twext:8240-8251
/CalendarServer/branches/users/glyph/parallel-upgrade/twext:8376-8400
/CalendarServer/branches/users/glyph/parallel-upgrade_to_1/twext:8571-8583
/CalendarServer/branches/users/glyph/q/twext:9560-9688
/CalendarServer/branches/users/glyph/queue-locking-and-timing/twext:10204-10289
/CalendarServer/branches/users/glyph/quota/twext:7604-7637
/CalendarServer/branches/users/glyph/sendfdport/twext:5388-5424
/CalendarServer/branches/users/glyph/shared-pool-fixes/twext:8436-8443
/CalendarServer/branches/users/glyph/shared-pool-take2/twext:8155-8174
/CalendarServer/branches/users/glyph/sharedpool/twext:6490-6550
/CalendarServer/branches/users/glyph/sharing-api/twext:9192-9205
/CalendarServer/branches/users/glyph/skip-lonely-vtimezones/twext:8524-8535
/CalendarServer/branches/users/glyph/sql-store/twext:5929-6073
/CalendarServer/branches/users/glyph/start-service-start-loop/twext:11060-11065
/CalendarServer/branches/users/glyph/subtransactions/twext:7248-7258
/CalendarServer/branches/users/glyph/table-alias/twext:8651-8664
/CalendarServer/branches/users/glyph/uidexport/twext:7673-7676
/CalendarServer/branches/users/glyph/unshare-when-access-revoked/twext:10562-10595
/CalendarServer/branches/users/glyph/use-system-twisted/twext:5084-5149
/CalendarServer/branches/users/glyph/uuid-normalize/twext:9268-9296
/CalendarServer/branches/users/glyph/warning-cleanups/twext:11347-11357
/CalendarServer/branches/users/glyph/whenNotProposed/twext:11881-11897
/CalendarServer/branches/users/glyph/xattrs-from-files/twext:7757-7769
/CalendarServer/branches/users/sagen/applepush/twext:8126-8184
/CalendarServer/branches/users/sagen/inboxitems/twext:7380-7381
/CalendarServer/branches/users/sagen/locations-resources/twext:5032-5051
/CalendarServer/branches/users/sagen/locations-resources-2/twext:5052-5061
/CalendarServer/branches/users/sagen/purge_old_events/twext:6735-6746
/CalendarServer/branches/users/sagen/resource-delegates-4038/twext:4040-4067
/CalendarServer/branches/users/sagen/resource-delegates-4066/twext:4068-4075
/CalendarServer/branches/users/sagen/resources-2/twext:5084-5093
/CalendarServer/branches/users/sagen/testing/twext:10827-10851,10853-10855
/CalendarServer/branches/users/wsanchez/transations/twext:5515-5593
/twext/branches/users/cdaboo/jobqueue-3/twext:13444-13471
/twext/branches/users/cdaboo/jobs/twext:12742-12780
/twext/branches/users/sagen/recordtypes/twext:13647-13658
/twext/branches/users/sagen/recordtypes-2/twext:13659

Modified: twext/trunk/twext/who/aggregate.py
===================================================================
--- twext/trunk/twext/who/aggregate.py	2014-06-18 21:13:12 UTC (rev 13659)
+++ twext/trunk/twext/who/aggregate.py	2014-06-18 21:13:47 UTC (rev 13660)
@@ -108,9 +108,10 @@
         return d
 
 
-    def recordsFromExpression(self, expression, records=None):
+    def recordsFromExpression(self, expression, recordTypes=None, records=None):
         return self._gatherFromSubServices(
-            "recordsFromExpression", expression, records=None
+            "recordsFromExpression", expression, recordTypes=recordTypes,
+            records=None
         )
 
 

Modified: twext/trunk/twext/who/directory.py
===================================================================
--- twext/trunk/twext/who/directory.py	2014-06-18 21:13:12 UTC (rev 13659)
+++ twext/trunk/twext/who/directory.py	2014-06-18 21:13:47 UTC (rev 13660)
@@ -122,7 +122,9 @@
         return self.recordType.iterconstants()
 
 
-    def recordsFromNonCompoundExpression(self, expression, records=None):
+    def recordsFromNonCompoundExpression(
+        self, expression, recordTypes=None, records=None
+    ):
         """
         Finds records matching a non-compound expression.
 
@@ -139,6 +141,10 @@
         @param expression: an expression to apply
         @type expression: L{object}
 
+        @param recordTypes: the record types to match
+        @type recordTypes: an iterable of L{NamedConstant}, or None for no
+            filtering
+
         @param records: a set of records to limit the search to. C{None} if
             the whole directory should be searched.
             This is provided by L{recordsFromExpression} when it has already
@@ -165,7 +171,9 @@
 
 
     @inlineCallbacks
-    def recordsFromCompoundExpression(self, expression, records=None):
+    def recordsFromCompoundExpression(
+        self, expression, recordTypes=None, records=None
+    ):
         """
         Finds records matching a compound expression.
 
@@ -178,6 +186,10 @@
         @param expression: an expression to apply
         @type expression: L{CompoundExpression}
 
+        @param recordTypes: the record types to match
+        @type recordTypes: an iterable of L{NamedConstant}, or None for no
+            filtering
+
         @param records: a set of records to limit the search to. C{None} if
             the whole directory should be searched.
             This is provided by L{recordsFromExpression} when it has already
@@ -201,7 +213,9 @@
             returnValue(())
 
         results = set((
-            yield self.recordsFromExpression(subExpression, records=records)
+            yield self.recordsFromExpression(
+                subExpression, recordTypes=recordTypes, records=records
+            )
         ))
 
         for subExpression in subExpressions:
@@ -216,7 +230,7 @@
 
             recordsMatchingExpression = frozenset((
                 yield self.recordsFromExpression(
-                    subExpression, records=records
+                    subExpression, recordTypes=recordTypes, records=records
                 )
             ))
 
@@ -232,16 +246,20 @@
         returnValue(results)
 
 
-    def recordsFromExpression(self, expression, records=None):
+    def recordsFromExpression(self, expression, recordTypes=None, records=None):
         """
         @note: This interface is the same as
             L{IDirectoryService.recordsFromExpression}, except for the
             additional C{records} argument.
         """
         if isinstance(expression, CompoundExpression):
-            return self.recordsFromCompoundExpression(expression)
+            return self.recordsFromCompoundExpression(
+                expression, recordTypes=recordTypes
+            )
         else:
-            return self.recordsFromNonCompoundExpression(expression)
+            return self.recordsFromNonCompoundExpression(
+                expression, recordTypes=recordTypes
+            )
 
 
     def recordsWithFieldValue(self, fieldName, value):

Modified: twext/trunk/twext/who/idirectory.py
===================================================================
--- twext/trunk/twext/who/idirectory.py	2014-06-18 21:13:12 UTC (rev 13659)
+++ twext/trunk/twext/who/idirectory.py	2014-06-18 21:13:47 UTC (rev 13660)
@@ -278,13 +278,17 @@
         """
 
 
-    def recordsFromExpression(expression):
+    def recordsFromExpression(expression, recordTypes=None):
         """
         Find records matching an expression.
 
         @param expression: an expression to apply
         @type expression: L{object}
 
+        @param recordTypes: the record types to match
+        @type recordTypes: an iterable of L{NamedConstant}, or None for no
+            filtering
+
         @return: The matching records.
         @rtype: deferred iterable of L{IDirectoryRecord}s
 

Modified: twext/trunk/twext/who/index.py
===================================================================
--- twext/trunk/twext/who/index.py	2014-06-18 21:13:12 UTC (rev 13659)
+++ twext/trunk/twext/who/index.py	2014-06-18 21:13:47 UTC (rev 13660)
@@ -226,7 +226,9 @@
         self._index = index
 
 
-    def indexedRecordsFromMatchExpression(self, expression, records=None):
+    def indexedRecordsFromMatchExpression(
+        self, expression, recordTypes=None, records=None
+    ):
         """
         Finds records in the internal indexes matching a single expression.
 
@@ -286,10 +288,17 @@
         # if records is not None:
         #     matchingRecords &= records
 
+        if recordTypes is not None:
+            for record in list(matchingRecords):
+                if record.recordType not in recordTypes:
+                    matchingRecords.remove(record)
+
         return succeed(matchingRecords)
 
 
-    def unIndexedRecordsFromMatchExpression(self, expression, records=None):
+    def unIndexedRecordsFromMatchExpression(
+        self, expression, recordTypes=None, records=None
+    ):
         """
         Finds records not in the internal indexes matching a single expression.
 
@@ -312,6 +321,11 @@
             )
 
         for record in records:
+
+            if recordTypes is not None:
+                if record.recordType not in recordTypes:
+                    continue
+
             fieldValues = record.fields.get(expression.fieldName, None)
 
             if fieldValues is None:
@@ -324,7 +338,9 @@
         return succeed(result)
 
 
-    def recordsFromNonCompoundExpression(self, expression, records=None):
+    def recordsFromNonCompoundExpression(
+        self, expression, recordTypes=None, records=None
+    ):
         """
         This implementation can handle L{MatchExpression} expressions; other
         expressions are passed up to the superclass.
@@ -332,15 +348,15 @@
         if isinstance(expression, MatchExpression):
             if expression.fieldName in self.indexedFields:
                 return self.indexedRecordsFromMatchExpression(
-                    expression, records=records
+                    expression, recordTypes=recordTypes, records=records
                 )
             else:
                 return self.unIndexedRecordsFromMatchExpression(
-                    expression, records=records
+                    expression, recordTypes=recordTypes, records=records
                 )
         else:
             return BaseDirectoryService.recordsFromNonCompoundExpression(
-                self, expression, records=records
+                self, expression, recordTypes=recordTypes, records=records
             )
 
 

Modified: twext/trunk/twext/who/ldap/_service.py
===================================================================
--- twext/trunk/twext/who/ldap/_service.py	2014-06-18 21:13:12 UTC (rev 13659)
+++ twext/trunk/twext/who/ldap/_service.py	2014-06-18 21:13:47 UTC (rev 13660)
@@ -408,7 +408,7 @@
 
 
     @inlineCallbacks
-    def _recordsFromQueryString(self, queryString):
+    def _recordsFromQueryString(self, queryString, recordTypes=None):
         connection = yield self._connect()
 
         self.log.info("Performing LDAP query: {query}", query=queryString)
@@ -428,7 +428,7 @@
             )
             raise LDAPQueryError("Unable to perform query", e)
 
-        records = yield self._recordsFromReply(reply)
+        records = yield self._recordsFromReply(reply, recordTypes=recordTypes)
         returnValue(records)
 
 
@@ -455,7 +455,7 @@
             returnValue(None)
 
 
-    def _recordsFromReply(self, reply):
+    def _recordsFromReply(self, reply, recordTypes=None):
         records = []
 
         for dn, recordData in reply:
@@ -474,6 +474,9 @@
                 )
                 continue
 
+            if recordTypes is not None and recordType not in recordTypes:
+                continue
+
             # Populate a fields dictionary
 
             fields = {}
@@ -527,20 +530,26 @@
         return records
 
 
-    def recordsFromNonCompoundExpression(self, expression, records=None):
+    def recordsFromNonCompoundExpression(
+        self, expression, recordTypes=None, records=None
+    ):
         if isinstance(expression, MatchExpression):
             queryString = ldapQueryStringFromMatchExpression(
                 expression,
                 self._fieldNameToAttributesMap, self._recordTypeSchemas
             )
-            return self._recordsFromQueryString(queryString)
+            return self._recordsFromQueryString(
+                queryString, recordTypes=recordTypes
+            )
 
         return BaseDirectoryService.recordsFromNonCompoundExpression(
             self, expression, records=records
         )
 
 
-    def recordsFromCompoundExpression(self, expression, records=None):
+    def recordsFromCompoundExpression(
+        self, expression, recordTypes=None, records=None
+    ):
         if not expression.expressions:
             return succeed(())
 
@@ -548,7 +557,9 @@
             expression,
             self._fieldNameToAttributesMap, self._recordTypeSchemas
         )
-        return self._recordsFromQueryString(queryString)
+        return self._recordsFromQueryString(
+            queryString, recordTypes=recordTypes
+        )
 
 
     # def updateRecords(self, records, create=False):

Modified: twext/trunk/twext/who/opendirectory/_service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/_service.py	2014-06-18 21:13:12 UTC (rev 13659)
+++ twext/trunk/twext/who/opendirectory/_service.py	2014-06-18 21:13:47 UTC (rev 13660)
@@ -390,7 +390,7 @@
         )
 
 
-    def _queryFromCompoundExpression(self, expression, local=False):
+    def _queryFromCompoundExpression(self, expression, recordTypes=None, local=False):
         """
         Form an OpenDirectory query from a compound expression.
 
@@ -410,22 +410,24 @@
         else:
             node = self.node
 
-        queryString, recordTypes = (
+        queryString, expressionRecordTypes = (
             self._queryStringAndRecordTypesFromExpression(expression)
         )
-        if not recordTypes:
-            return None
 
         # Scrub unsupported recordTypes
         supportedODRecordTypes = []
-        for rt in self.recordTypes():
-            odRecordType = ODRecordType.fromRecordType(rt)
+        for recordType in self.recordTypes():
+            odRecordType = ODRecordType.fromRecordType(recordType)
             if odRecordType is not None:
                 supportedODRecordTypes.append(odRecordType.value)
-        scrubbedRecordTypes = []
-        for recordType in recordTypes:
-            if recordType in supportedODRecordTypes:
-                scrubbedRecordTypes.append(recordType)
+        if recordTypes is not None:
+            scrubbedRecordTypes = []
+            for recordType in recordTypes:
+                recordType = ODRecordType.fromRecordType(recordType).value
+                if recordType in supportedODRecordTypes:
+                    scrubbedRecordTypes.append(recordType)
+        else:
+            scrubbedRecordTypes = supportedODRecordTypes
 
         if not scrubbedRecordTypes:
             # None of the requested recordTypes are supported.
@@ -464,7 +466,7 @@
 
 
     def _queryFromMatchExpression(
-        self, expression, recordType=None, local=False
+        self, expression, recordTypes=None, local=False
     ):
         """
         Form an OpenDirectory query from a match expression.
@@ -472,8 +474,8 @@
         @param expression: A match expression.
         @type expression: L{MatchExpression}
 
-        @param recordType: A record type to insert into the query.
-        @type recordType: L{NamedConstant}
+        @param recordTypes: Record types to insert into the query; None for no filtering.
+        @type recordTypes: iterable of L{NamedConstant}, or None
 
         @param local: Whether to restrict the query to the local node
         @type local: C{Boolean}
@@ -506,47 +508,27 @@
             expression.fieldName = self.fieldName.guid
 
         if expression.fieldName is self.fieldName.recordType:
-            if (
-                recordType is not None and
-                expression.fieldValue is not recordType
-            ):
-                raise ValueError(
-                    "recordType argument does not match expression"
-                )
+            raise QueryNotSupportedError("RecordType match not supported")
 
-            recordTypes = [
-                ODRecordType.fromRecordType(expression.fieldValue).value
-            ]
-            if MatchFlags.NOT in flags:
-                recordTypes = list(
-                    set([t.value for t in ODRecordType.iterconstants()]) -
-                    recordTypes
-                )
+        if MatchFlags.NOT in flags:
+            raise NotImplementedError()
 
-            matchType = ODMatchType.any.value
-            queryAttribute = None
-            queryValue = None
-
+        if recordTypes is None:
+            odRecordTypes = [t.value for t in ODRecordType.iterconstants()]
         else:
-            if MatchFlags.NOT in flags:
-                raise NotImplementedError()
+            odRecordTypes = [ODRecordType.fromRecordType(r).value for r in recordTypes]
 
-            if recordType is None:
-                recordTypes = [t.value for t in ODRecordType.iterconstants()]
-            else:
-                recordTypes = [ODRecordType.fromRecordType(recordType).value]
+        queryAttribute = ODAttribute.fromFieldName(
+            expression.fieldName
+        ).value
 
-            queryAttribute = ODAttribute.fromFieldName(
-                expression.fieldName
-            ).value
+        # TODO: Add support other value types:
+        valueType = self.fieldName.valueType(expression.fieldName)
+        if valueType == UUID:
+            queryValue = unicode(expression.fieldValue).upper()
+        else:
+            queryValue = unicode(expression.fieldValue)
 
-            # TODO: Add support other value types:
-            valueType = self.fieldName.valueType(expression.fieldName)
-            if valueType == UUID:
-                queryValue = unicode(expression.fieldValue).upper()
-            else:
-                queryValue = unicode(expression.fieldValue)
-
         if local:
             node = self.localNode
         else:
@@ -559,9 +541,9 @@
             if odRecordType is not None:
                 supportedODRecordTypes.append(odRecordType.value)
         scrubbedRecordTypes = []
-        for recordType in recordTypes:
-            if recordType in supportedODRecordTypes:
-                scrubbedRecordTypes.append(recordType)
+        for odRecordType in odRecordTypes:
+            if odRecordType in supportedODRecordTypes:
+                scrubbedRecordTypes.append(odRecordType)
 
         if not scrubbedRecordTypes:
             # None of the requested recordTypes are supported.
@@ -704,10 +686,10 @@
         return succeed(result)
 
 
-    def recordsFromNonCompoundExpression(self, expression, records=None):
+    def recordsFromNonCompoundExpression(self, expression, recordTypes=None, records=None):
         if isinstance(expression, MatchExpression):
             try:
-                query = self._queryFromMatchExpression(expression)
+                query = self._queryFromMatchExpression(expression, recordTypes=recordTypes)
                 return self._recordsFromQuery(query)
 
             except QueryNotSupportedError:
@@ -722,7 +704,7 @@
 
 
     @inlineCallbacks
-    def recordsFromCompoundExpression(self, expression, records=None):
+    def recordsFromCompoundExpression(self, expression, recordTypes=None, records=None):
         """
         Returns records matching the CompoundExpression.  Because the
         local node doesn't perform Compound queries in a case insensitive
@@ -733,13 +715,13 @@
         """
 
         try:
-            query = self._queryFromCompoundExpression(expression)
+            query = self._queryFromCompoundExpression(expression, recordTypes=recordTypes)
 
         except QueryNotSupportedError:
             returnValue(
                 (
                     yield BaseDirectoryService.recordsFromCompoundExpression(
-                        self, expression
+                        self, expression, recordTypes=recordTypes
                     )
                 )
             )
@@ -749,7 +731,7 @@
         if self.localNode is not None:
 
             localRecords = yield self.localRecordsFromCompoundExpression(
-                expression
+                expression, recordTypes=recordTypes
             )
             for localRecord in localRecords:
                 if localRecord not in results:
@@ -760,7 +742,7 @@
 
 
     @inlineCallbacks
-    def localRecordsFromCompoundExpression(self, expression):
+    def localRecordsFromCompoundExpression(self, expression, recordTypes=None):
         """
         Takes a CompoundExpression, and recursively goes through each
         MatchExpression, passing those specifically to the local node, and
@@ -778,13 +760,13 @@
 
             if isinstance(subExpression, CompoundExpression):
                 subRecords = yield self.localRecordsFromCompoundExpression(
-                    subExpression
+                    subExpression, recordTypes=recordTypes
                 )
 
             elif isinstance(subExpression, MatchExpression):
                 try:
                     subQuery = self._queryFromMatchExpression(
-                        subExpression, local=True
+                        subExpression, recordTypes=recordTypes, local=True
                     )
                 except UnsupportedRecordTypeError:
                     continue
@@ -857,7 +839,7 @@
         try:
             query = self._queryFromMatchExpression(
                 MatchExpression(self.fieldName.shortNames, shortName),
-                recordType=recordType
+                recordTypes=(recordType,)
             )
             results = yield self._recordsFromQuery(query)
 

Modified: twext/trunk/twext/who/test/test_directory.py
===================================================================
--- twext/trunk/twext/who/test/test_directory.py	2014-06-18 21:13:12 UTC (rev 13659)
+++ twext/trunk/twext/who/test/test_directory.py	2014-06-18 21:13:47 UTC (rev 13660)
@@ -62,15 +62,17 @@
         self.seenExpressions = []
 
 
-    def recordsFromExpression(self, expression, records=None):
+    def recordsFromExpression(self, expression, recordTypes=None, records=None):
         self.seenExpressions.append(expression)
         return (
             super(StubDirectoryService, self)
-            .recordsFromExpression(expression)
+            .recordsFromExpression(expression, recordTypes=recordTypes)
         )
 
 
-    def recordsFromNonCompoundExpression(self, expression, records=None):
+    def recordsFromNonCompoundExpression(
+        self, expression, recordTypes=None, records=None
+    ):
         """
         This implementation handles three expressions:
 
@@ -94,7 +96,9 @@
 
         return (
             super(StubDirectoryService, self)
-            .recordsFromNonCompoundExpression(expression, records=records)
+            .recordsFromNonCompoundExpression(
+                expression, recordTypes=recordTypes, records=records
+            )
         )
 
 
@@ -1149,7 +1153,23 @@
             ],
         )
 
+        self.addGroup(
+            shortNames=[u"calendar-dev"],
+            fullNames=[u"Calendar Developers"],
+            emailAddresses=[
+                u"calendar-dev at example.com",
+            ],
+        )
 
+        self.addGroup(
+            shortNames=[u"developers"],
+            fullNames=[u"Developers"],
+            emailAddresses=[
+                u"developers at example.com",
+            ],
+        )
+
+
     def addUser(self, shortNames, fullNames, emailAddresses=[]):
         """
         Add a user record with the given field information.
@@ -1177,6 +1197,32 @@
         }))
 
 
+    def addGroup(self, shortNames, fullNames, emailAddresses=[]):
+        """
+        Add a group record with the given field information.
+
+        @param shortNames: Record short names.
+        @type shortNames: L{list} of L{unicode}s
+
+        @param fullNames: Record full names.
+        @type fullNames: L{list} of L{unicode}s
+
+        @param emailAddresses: Record email addresses.
+        @type emailAddresses: L{list} of L{unicode}s
+        """
+        service = self.service
+        fieldName = service.fieldName
+        recordType = service.recordType
+
+        self.records.append(self.recordClass(self.service, {
+            fieldName.recordType: recordType.group,
+            fieldName.uid: u"__{0}__".format(shortNames[0]),
+            fieldName.shortNames: shortNames,
+            fieldName.fullNames: fullNames,
+            fieldName.emailAddresses: emailAddresses,
+        }))
+
+
     def __iter__(self):
         return iter(self.records)
 

Modified: twext/trunk/twext/who/test/test_index.py
===================================================================
--- twext/trunk/twext/who/test/test_index.py	2014-06-18 21:13:12 UTC (rev 13659)
+++ twext/trunk/twext/who/test/test_index.py	2014-06-18 21:13:47 UTC (rev 13660)
@@ -149,6 +149,7 @@
     @inlineCallbacks
     def _test_indexedRecordsFromMatchExpression(
         self, inOut, matchType, fieldName=BaseFieldName.shortNames,
+        recordTypes=None
     ):
         service = self.noLoadServicePopulated()
 
@@ -157,7 +158,8 @@
                 MatchExpression(
                     fieldName, subString,
                     matchType
-                )
+                ),
+                recordTypes=recordTypes,
             )
             self.assertEquals(
                 set((record.uid for record in records)),
@@ -238,9 +240,25 @@
         self.assertFailure(result, NotImplementedError)
 
 
+    def test_indexedRecordsFromMatchExpression_recordTypes(self):
+        """
+        L{DirectoryService.indexedRecordsFromMatchExpression} with recordTypes
+        """
+        return self._test_indexedRecordsFromMatchExpression(
+            (
+                (u"c", (u"__calendar-dev__",)),  # only groups
+                (u"d", (u"__developers__",)),
+                (u"j", ()),
+            ),
+            MatchType.startsWith,
+            recordTypes=(BaseRecordType.group,)
+        )
+
+
     @inlineCallbacks
     def _test_unIndexedRecordsFromMatchExpression(
         self, inOut, matchType, fieldName=BaseFieldName.fullNames,
+        recordTypes=None
     ):
         service = self.noLoadServicePopulated()
 
@@ -249,7 +267,8 @@
                 MatchExpression(
                     fieldName, subString,
                     matchType
-                )
+                ),
+                recordTypes=recordTypes
             )
             self.assertEquals(
                 set((record.uid for record in records)),

Modified: twext/trunk/twext/who/test/test_xml.py
===================================================================
--- twext/trunk/twext/who/test/test_xml.py	2014-06-18 21:13:12 UTC (rev 13659)
+++ twext/trunk/twext/who/test/test_xml.py	2014-06-18 21:13:47 UTC (rev 13660)
@@ -557,7 +557,28 @@
         self.assertRecords(records, (u"__wsanchez__",))
 
 
+    @inlineCallbacks
+    def test_queryWithRecordTypes(self):
+        """
+        Verify that results are limited to the requested recordTypes
+        """
+        service = self.service()
+        records = yield service.recordsFromExpression(
+            service.query(
+                u"fullNames", u"e",
+                matchType=MatchType.contains,
+            ),
+            recordTypes=(service.recordType.group,)
+        )
+        # Note: only contains groups; the users that would normally match
+        # have been filtered out
+        self.assertRecords(
+            records,
+            (u"__calendar-dev__", u"__developers__", u"__twisted__")
+        )
 
+
+
 class DirectoryServiceMutableTestMixIn(object):
     @inlineCallbacks
     def test_updateRecord(self):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140618/44514c22/attachment-0001.html>


More information about the calendarserver-changes mailing list