[CalendarServer-changes] [12612] twext/trunk/twext/who/opendirectory/_service.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:16:17 PDT 2014
Revision: 12612
http://trac.calendarserver.org//changeset/12612
Author: wsanchez at apple.com
Date: 2014-02-07 12:43:59 -0800 (Fri, 07 Feb 2014)
Log Message:
-----------
recordWithShortName() no longer does a compound query.
Raise QueryNotSupportedError in _queryStringFromMatchExpression() if record type is part of the query, since that's can't be expressed in a query string.
Add recordType argument to _queryFromMatchExpression() so that we can insert a record type filter.
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-02-07 20:30:52 UTC (rev 12611)
+++ twext/trunk/twext/who/opendirectory/_service.py 2014-02-07 20:43:59 UTC (rev 12612)
@@ -239,6 +239,12 @@
if expression.fieldName is self.fieldName.uid:
odAttr = ODAttribute.guid
value = expression.fieldValue
+
+ elif expression.fieldName is self.fieldName.recordType:
+ raise QueryNotSupportedError(
+ "Can't build a query string for record types."
+ )
+
else:
odAttr = ODAttribute.fromFieldName(expression.fieldName)
if odAttr is None:
@@ -350,13 +356,16 @@
return query
- def _queryFromMatchExpression(self, expression):
+ def _queryFromMatchExpression(self, expression, recordType=None):
"""
Form an OpenDirectory query from a match expression.
@param expression: A match expression.
@type expression: L{MatchExpression}
+ @param recordType: A record type to insert into the query.
+ @type recordType: L{NamedConstant}
+
@return: A native OpenDirectory query.
@rtype: L{ODQuery}
"""
@@ -388,6 +397,14 @@
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"
+ )
+
recordTypes = ODRecordType.fromRecordType(
expression.fieldValue
).value
@@ -396,11 +413,16 @@
queryValue = None
else:
- recordTypes = [t.value for t in ODRecordType.iterconstants()]
+ if recordType is None:
+ recordTypes = [t.value for t in ODRecordType.iterconstants()]
+ else:
+ recordTypes = recordType
+
queryAttribute = ODAttribute.fromFieldName(
expression.fieldName
).value
- # TODO: support other valuetypes:
+
+ # TODO: Add support other valuetypes:
valueType = self.fieldName.valueType(expression.fieldName)
if valueType == UUID:
queryValue = unicode(expression.fieldValue).upper()
@@ -480,7 +502,7 @@
return self._recordsFromQuery(query)
except QueryNotSupportedError:
- pass
+ pass # Let the superclass try
return BaseDirectoryService.recordsFromNonCompoundExpression(
self, expression
@@ -517,7 +539,22 @@
return record
+ def recordWithShortName(self, recordType, shortName):
+ try:
+ query = self._queryFromMatchExpression(
+ MatchExpression(self.fieldName.shortNames, shortName),
+ recordType=recordType
+ )
+ return self._recordsFromQuery(query)
+ except QueryNotSupportedError:
+ # Let the superclass try
+ return BaseDirectoryService.recordWithShortName(
+ self, recordType, shortName
+ )
+
+
+
@implementer(IPlaintextPasswordVerifier, IHTTPDigestVerifier)
class DirectoryRecord(BaseDirectoryRecord):
"""
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/d14cb77f/attachment.html>
More information about the calendarserver-changes
mailing list