[CalendarServer-changes] [13652] twext/branches/users/sagen/recordtypes/twext/who/opendirectory/ _service.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jun 18 13:26:19 PDT 2014
Revision: 13652
http://trac.calendarserver.org//changeset/13652
Author: sagen at apple.com
Date: 2014-06-18 13:26:18 -0700 (Wed, 18 Jun 2014)
Log Message:
-----------
Support for recordTypes arg
Modified Paths:
--------------
twext/branches/users/sagen/recordtypes/twext/who/opendirectory/_service.py
Modified: twext/branches/users/sagen/recordtypes/twext/who/opendirectory/_service.py
===================================================================
--- twext/branches/users/sagen/recordtypes/twext/who/opendirectory/_service.py 2014-06-18 18:06:15 UTC (rev 13651)
+++ twext/branches/users/sagen/recordtypes/twext/who/opendirectory/_service.py 2014-06-18 20:26:18 UTC (rev 13652)
@@ -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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140618/88aca6b9/attachment.html>
More information about the calendarserver-changes
mailing list