[CalendarServer-changes] [12116] twext/trunk/twext/who/opendirectory/service.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:23:45 PDT 2014
Revision: 12116
http://trac.calendarserver.org//changeset/12116
Author: wsanchez at apple.com
Date: 2013-12-16 18:48:22 -0800 (Mon, 16 Dec 2013)
Log Message:
-----------
cleanup, docs
Modified Paths:
--------------
twext/trunk/twext/who/opendirectory/service.py
Modified: twext/trunk/twext/who/opendirectory/service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/service.py 2013-12-17 02:33:52 UTC (rev 12115)
+++ twext/trunk/twext/who/opendirectory/service.py 2013-12-17 02:48:22 UTC (rev 12116)
@@ -29,7 +29,7 @@
from itertools import chain
-import odframework
+from odframework import ODSession, ODNode, ODQuery
from twext.python.log import Logger
from twisted.python.constants import Names, NamedConstant
@@ -309,9 +309,9 @@
@raises: L{OpenDirectoryConnectionError} if unable to connect.
"""
if not hasattr(self, "_session"):
- session = odframework.ODSession.defaultSession()
+ session = ODSession.defaultSession()
- node, error = odframework.ODNode.nodeWithSession_name_error_(
+ node, error = ODNode.nodeWithSession_name_error_(
session, self.nodeName, None
)
@@ -328,6 +328,15 @@
def _queryFromMatchExpression(self, expression):
+ """
+ Form an OpenDirectory query from a match expression.
+
+ @param expression: The match expression.
+ @type expression: L{MatchExpression}
+
+ @return: A native OpenDirectory query.
+ @rtype: L{ODQuery}
+ """
if not isinstance(expression, MatchExpression):
raise TypeError(expression)
@@ -350,7 +359,7 @@
attributes = [a.value for a in ODAttribute.iterconstants()]
maxResults = 0
- query, error = odframework.ODQuery.queryWithNode_forRecordTypes_attribute_matchType_queryValues_returnAttributes_maximumResults_error_(
+ query, error = ODQuery.queryWithNode_forRecordTypes_attribute_matchType_queryValues_returnAttributes_maximumResults_error_(
self.node,
recordTypes,
ODAttribute.fromFieldName(expression.fieldName).value,
@@ -372,6 +381,16 @@
def _adaptODRecord(self, odRecord):
+ """
+ Adapt a native OpenDirectory record to a L{DirectoryRecord}.
+
+ @param odRecord: A native OpenDirectory record.
+ @type odRecord: L{ODRecord}
+
+ @return: A directory record with the fields matching the attributes of
+ C{odRecord}.
+ @rtype: L{DirectoryRecord}
+ """
details, error = odRecord.recordDetailsForAttributes_error_(None, None)
if error:
@@ -418,6 +437,15 @@
def _recordsFromQuery(self, query):
+ """
+ Executes a query and generates directory records from it.
+
+ @param query: A query.
+ @type query: L{ODQuery}
+
+ @return: The records produced by executing the query.
+ @rtype: iterable of L{DirectoryRecord}
+ """
odRecords, error = query.resultsAllowingPartial_error_(False, None)
if error:
@@ -432,31 +460,35 @@
def recordsFromMatchExpression(self, expression):
+ """
+ Find records matching a match expression.
+
+ @param expression: an expression to apply
+ @type expression: L{MatchExpression}
+
+ @return: The matching records.
+ @rtype: deferred iterable of L{IDirectoryRecord}s
+
+ @raises: L{QueryNotSupportedError} if the expression is not
+ supported by this directory service.
+ """
query = self._queryFromMatchExpression(expression)
return self._recordsFromQuery(query)
def recordsFromExpression(self, expression):
- """
- This implementation can handle L{MatchExpression} expressions; other
- expressions are passed up to the superclass.
- """
- if isinstance(expression, CompoundExpression):
- raise NotImplementedError(Operand)
-
- elif isinstance(expression, MatchExpression):
- try:
+ try:
+ if isinstance(expression, CompoundExpression):
+ raise NotImplementedError(Operand)
+ elif isinstance(expression, MatchExpression):
return self.recordsFromMatchExpression(expression)
- except QueryNotSupportedError:
- return BaseDirectoryService.recordsFromExpression(
- self, expression
- )
- else:
- return BaseDirectoryService.recordsFromExpression(
- self, expression
- )
+ except QueryNotSupportedError:
+ pass
+ return BaseDirectoryService.recordsFromExpression(
+ self, expression
+ )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/a0e0e576/attachment.html>
More information about the calendarserver-changes
mailing list