[CalendarServer-changes] [10618] CalendarServer/trunk/twext/who
source_changes at macosforge.org
source_changes at macosforge.org
Fri Feb 1 11:01:54 PST 2013
Revision: 10618
http://trac.calendarserver.org//changeset/10618
Author: wsanchez at apple.com
Date: 2013-02-01 11:01:54 -0800 (Fri, 01 Feb 2013)
Log Message:
-----------
Don't forget to defer.
Modified Paths:
--------------
CalendarServer/trunk/twext/who/directory.py
CalendarServer/trunk/twext/who/test/test_directory.py
CalendarServer/trunk/twext/who/test/test_xml.py
CalendarServer/trunk/twext/who/xml.py
Modified: CalendarServer/trunk/twext/who/directory.py
===================================================================
--- CalendarServer/trunk/twext/who/directory.py 2013-02-01 17:46:16 UTC (rev 10617)
+++ CalendarServer/trunk/twext/who/directory.py 2013-02-01 19:01:54 UTC (rev 10618)
@@ -26,6 +26,8 @@
from zope.interface import implements
from twisted.python.util import FancyEqMixin
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.internet.defer import succeed, fail
from twext.who.idirectory import DirectoryServiceError
from twext.who.idirectory import QueryNotSupportedError
@@ -59,29 +61,30 @@
def recordTypes(self):
- return self.RecordTypeClass.iterconstants()
+ return succeed(self.RecordTypeClass.iterconstants())
def recordsFromExpression(self, expression):
- raise QueryNotSupportedError("Unknown expression: %s" % (expression,))
+ return fail(QueryNotSupportedError("Unknown expression: %s" % (expression,)))
+ @inlineCallbacks
def recordsFromQuery(self, expressions, operand=Operand.AND):
expressionIterator = iter(expressions)
try:
expression = expressionIterator.next()
except StopIteration:
- return set()
+ returnValue(set())
- results = self.recordsFromExpression(expression)
+ results = (yield self.recordsFromExpression(expression))
for expression in expressions:
if (operand == Operand.AND and not results):
# No need to bother continuing here
- return set()
+ returnValue(set())
- recordsMatchingExpression = self.recordsFromExpression(expression)
+ recordsMatchingExpression = (yield self.recordsFromExpression(expression))
if operand == Operand.AND:
results &= recordsMatchingExpression
@@ -90,26 +93,30 @@
else:
raise QueryNotSupportedError("Unknown operand: %s" % (operand,))
- return results
+ returnValue(results)
+ @inlineCallbacks
def recordsWithFieldValue(self, fieldName, value):
- return self.recordsFromExpression(DirectoryQueryMatchExpression(fieldName, value))
+ returnValue((yield self.recordsFromExpression(DirectoryQueryMatchExpression(fieldName, value))))
+ @inlineCallbacks
def recordWithUID(self, uid):
- return uniqueResult(self.recordsWithFieldValue(FieldName.uid, uid))
+ returnValue(uniqueResult((yield self.recordsWithFieldValue(FieldName.uid, uid))))
+ @inlineCallbacks
def recordWithGUID(self, guid):
- return uniqueResult(self.recordsWithFieldValue(FieldName.guid, guid))
+ returnValue(uniqueResult((yield self.recordsWithFieldValue(FieldName.guid, guid))))
def recordsWithRecordType(self, recordType):
return self.recordsWithFieldValue(FieldName.recordType, recordType)
+ @inlineCallbacks
def recordWithShortName(self, recordType, shortName):
- return uniqueResult(self.recordsFromQuery((
+ returnValue(uniqueResult((yield self.recordsFromQuery((
DirectoryQueryMatchExpression(FieldName.recordType, recordType),
DirectoryQueryMatchExpression(FieldName.shortNames, shortName ),
- )))
+ )))))
def recordsWithEmailAddress(self, emailAddress):
return self.recordsWithFieldValue(FieldName.emailAddresses, emailAddress)
Modified: CalendarServer/trunk/twext/who/test/test_directory.py
===================================================================
--- CalendarServer/trunk/twext/who/test/test_directory.py 2013-02-01 17:46:16 UTC (rev 10617)
+++ CalendarServer/trunk/twext/who/test/test_directory.py 2013-02-01 19:01:54 UTC (rev 10618)
@@ -22,6 +22,7 @@
from twisted.trial import unittest
from twisted.trial.unittest import SkipTest
+from twisted.internet.defer import inlineCallbacks
from twext.who.idirectory import QueryNotSupportedError
from twext.who.idirectory import RecordType, FieldName
@@ -55,24 +56,26 @@
self.assertEquals(service.realmName, self.realmName)
+ @inlineCallbacks
def test_recordTypes(self):
service = self._testService()
self.assertEquals(
- set(service.recordTypes()),
+ set((yield service.recordTypes())),
set(service.RecordTypeClass.iterconstants())
)
+ @inlineCallbacks
def test_recordsFromQueryNone(self):
service = self._testService()
- records = service.recordsFromQuery(())
+ records = (yield service.recordsFromQuery(()))
for record in records:
self.failTest("No records expected")
def test_recordsFromQueryBogus(self):
service = self._testService()
- self.assertRaises(QueryNotSupportedError, service.recordsFromQuery, (object(),))
+ self.assertFailure(service.recordsFromQuery((object(),)), QueryNotSupportedError)
def test_recordWithUID(self):
Modified: CalendarServer/trunk/twext/who/test/test_xml.py
===================================================================
--- CalendarServer/trunk/twext/who/test/test_xml.py 2013-02-01 17:46:16 UTC (rev 10617)
+++ CalendarServer/trunk/twext/who/test/test_xml.py 2013-02-01 19:01:54 UTC (rev 10618)
@@ -19,6 +19,7 @@
"""
from twisted.python.filepath import FilePath
+from twisted.internet.defer import inlineCallbacks
from twext.who.idirectory import RecordType
from twext.who.xml import DirectoryService
@@ -69,36 +70,40 @@
class DirectoryServiceTest(BaseTest, test_directory.DirectoryServiceTest):
+ @inlineCallbacks
def test_recordWithUID(self):
service = self._testService()
- record = service.recordWithUID("wsanchez")
+ record = (yield service.recordWithUID("wsanchez"))
self.assertEquals(record.uid, "wsanchez")
+ @inlineCallbacks
def test_recordWithGUID(self):
service = self._testService()
- record = service.recordWithGUID("wsanchez")
+ record = (yield service.recordWithGUID("wsanchez"))
self.assertEquals(record, None)
-
+ @inlineCallbacks
def test_recordsWithRecordType(self):
service = self._testService()
- records = service.recordsWithRecordType(RecordType.user)
+ records = (yield service.recordsWithRecordType(RecordType.user))
self.assertEquals(
set((record.uid for record in records)),
set(("wsanchez", "glyph")),
)
+ @inlineCallbacks
def test_recordWithShortName(self):
service = self._testService()
- record = service.recordWithShortName(RecordType.user, "wsanchez")
+ record = (yield service.recordWithShortName(RecordType.user, "wsanchez"))
self.assertEquals(record.uid, "wsanchez")
+ @inlineCallbacks
def test_recordsWithEmailAddress(self):
service = self._testService()
- records = service.recordsWithEmailAddress("wsanchez at example.com")
+ records = (yield service.recordsWithEmailAddress("wsanchez at example.com"))
self.assertEquals(
set((record.uid for record in records)),
set(("wsanchez",)),
Modified: CalendarServer/trunk/twext/who/xml.py
===================================================================
--- CalendarServer/trunk/twext/who/xml.py 2013-02-01 17:46:16 UTC (rev 10617)
+++ CalendarServer/trunk/twext/who/xml.py 2013-02-01 19:01:54 UTC (rev 10618)
@@ -29,6 +29,7 @@
from xml.etree.ElementTree import ParseError as XMLParseError
from twisted.python.constants import Values, ValueConstant
+from twisted.internet.defer import succeed, inlineCallbacks, returnValue
from twext.who.idirectory import DirectoryServiceError
from twext.who.idirectory import RecordType, FieldName
@@ -248,15 +249,16 @@
if expression.flags:
raise NotImplementedError("Handle QueryFlags")
- return self.index[expression.fieldName].get(expression.fieldValue, ())
+ return succeed(self.index[expression.fieldName].get(expression.fieldValue, ()))
+ @inlineCallbacks
def recordsFromExpression(self, expression):
if isinstance(expression, DirectoryQueryMatchExpression):
if expression.fieldName in self.indexedFields:
- return self.indexedRecordsFromMatchExpression(expression)
+ returnValue((yield self.indexedRecordsFromMatchExpression(expression)))
raise NotImplementedError("Handle unindexed field")
else:
- return BaseDirectoryService.recordsFromExpression(self, expression)
+ returnValue((yield BaseDirectoryService.recordsFromExpression(self, expression)))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130201/33974c81/attachment-0001.html>
More information about the calendarserver-changes
mailing list