[CalendarServer-changes] [12161] twext/trunk/twext/who/directory.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:19:46 PDT 2014
Revision: 12161
http://trac.calendarserver.org//changeset/12161
Author: wsanchez at apple.com
Date: 2013-12-19 18:06:01 -0800 (Thu, 19 Dec 2013)
Log Message:
-----------
Add self.recordsFromCompoundExpression()
Modified Paths:
--------------
twext/trunk/twext/who/directory.py
Modified: twext/trunk/twext/who/directory.py
===================================================================
--- twext/trunk/twext/who/directory.py 2013-12-20 02:05:41 UTC (rev 12160)
+++ twext/trunk/twext/who/directory.py 2013-12-20 02:06:01 UTC (rev 12161)
@@ -116,7 +116,7 @@
def recordsFromNonCompoundExpression(self, expression, records=None):
"""
- Finds records matching a expression.
+ Finds records matching a non-compound expression.
@note: This method is called by L{recordsFromExpression} to handle
all expressions other than L{CompoundExpression}.
@@ -157,45 +157,67 @@
@inlineCallbacks
- def recordsFromExpression(self, expression):
- if isinstance(expression, CompoundExpression):
- operand = expression.operand
- subExpressions = iter(expression.expressions)
+ def recordsFromCompoundExpression(self, expression):
+ """
+ Finds records matching a compound expression.
- try:
- subExpression = subExpressions.next()
- except StopIteration:
- returnValue(())
+ @note: This method is called by L{recordsFromExpression} to handle
+ all L{CompoundExpression}s.
- results = set((
- yield self.recordsFromNonCompoundExpression(subExpression)
+ @param expression: an expression to apply
+ @type expression: L{CompoundExpression}
+
+ @return: The matching records.
+ @rtype: deferred iterable of L{IDirectoryRecord}s
+
+ @raises: L{QueryNotSupportedError} if the expression is not
+ supported by this directory service.
+ """
+ operand = expression.operand
+ subExpressions = iter(expression.expressions)
+
+ try:
+ subExpression = subExpressions.next()
+ except StopIteration:
+ returnValue(())
+
+ results = set((
+ yield self.recordsFromNonCompoundExpression(subExpression)
+ ))
+
+ for subExpression in subExpressions:
+ if operand == Operand.AND:
+ if not results:
+ # No need to bother continuing here
+ returnValue(())
+
+ records = results
+ else:
+ records = None
+
+ recordsMatchingExpression = frozenset((
+ yield self.recordsFromNonCompoundExpression(
+ subExpression,
+ records=records
+ )
))
- for subExpression in subExpressions:
- if operand == Operand.AND:
- if not results:
- # No need to bother continuing here
- returnValue(())
+ if operand == Operand.AND:
+ results &= recordsMatchingExpression
+ elif operand == Operand.OR:
+ results |= recordsMatchingExpression
+ else:
+ raise QueryNotSupportedError(
+ "Unknown operand: {0}".format(operand)
+ )
- records = results
- else:
- records = None
+ returnValue(results)
- recordsMatchingExpression = frozenset((
- yield self.recordsFromNonCompoundExpression(
- subExpression,
- records=records
- )
- ))
- if operand == Operand.AND:
- results &= recordsMatchingExpression
- elif operand == Operand.OR:
- results |= recordsMatchingExpression
- else:
- raise QueryNotSupportedError(
- "Unknown operand: {0}".format(operand)
- )
+ @inlineCallbacks
+ def recordsFromExpression(self, expression):
+ if isinstance(expression, CompoundExpression):
+ results = yield self.recordsFromCompoundExpression(expression)
else:
results = yield self.recordsFromNonCompoundExpression(expression)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/0fdf5b40/attachment.html>
More information about the calendarserver-changes
mailing list