<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[13948] twext/trunk/twext/who</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/13948">13948</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-09-10 20:32:22 -0700 (Wed, 10 Sep 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Adds limitResults and timeoutSeconds to twext.who API; greatly speeds up LDAP group expansion</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#twexttrunktwextwhoaggregatepy">twext/trunk/twext/who/aggregate.py</a></li>
<li><a href="#twexttrunktwextwhodirectorypy">twext/trunk/twext/who/directory.py</a></li>
<li><a href="#twexttrunktwextwhoidirectorypy">twext/trunk/twext/who/idirectory.py</a></li>
<li><a href="#twexttrunktwextwhoindexpy">twext/trunk/twext/who/index.py</a></li>
<li><a href="#twexttrunktwextwholdap_servicepy">twext/trunk/twext/who/ldap/_service.py</a></li>
<li><a href="#twexttrunktwextwholdaptesttest_servicepy">twext/trunk/twext/who/ldap/test/test_service.py</a></li>
<li><a href="#twexttrunktwextwhoopendirectory_servicepy">twext/trunk/twext/who/opendirectory/_service.py</a></li>
<li><a href="#twexttrunktwextwhotesttest_directorypy">twext/trunk/twext/who/test/test_directory.py</a></li>
<li><a href="#twexttrunktwextwhotesttest_indexpy">twext/trunk/twext/who/test/test_index.py</a></li>
<li><a href="#twexttrunktwextwhotesttest_xmlpy">twext/trunk/twext/who/test/test_xml.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="twexttrunktwextwhoaggregatepy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/aggregate.py (13947 => 13948)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/aggregate.py        2014-09-10 14:52:49 UTC (rev 13947)
+++ twext/trunk/twext/who/aggregate.py        2014-09-11 03:32:22 UTC (rev 13948)
</span><span class="lines">@@ -109,10 +109,14 @@
</span><span class="cx"> return d
</span><span class="cx">
</span><span class="cx">
</span><del>- def recordsFromExpression(self, expression, recordTypes=None, records=None):
</del><ins>+ def recordsFromExpression(
+ self, expression, recordTypes=None, records=None,
+ limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> return self._gatherFromSubServices(
</span><span class="cx"> "recordsFromExpression", expression, recordTypes=recordTypes,
</span><del>- records=None
</del><ins>+ records=None,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -123,41 +127,58 @@
</span><span class="cx"> # want to call their implementations, not bypass them.
</span><span class="cx">
</span><span class="cx">
</span><del>- def recordsWithFieldValue(self, fieldName, value):
</del><ins>+ def recordsWithFieldValue(
+ self, fieldName, value, limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> return self._gatherFromSubServices(
</span><del>- "recordsWithFieldValue", fieldName, value
</del><ins>+ "recordsWithFieldValue", fieldName, value,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><del>- def recordWithUID(self, uid):
- return self._oneFromSubServices("recordWithUID", uid)
</del><ins>+ def recordWithUID(self, uid, timeoutSeconds=None):
+ return self._oneFromSubServices(
+ "recordWithUID", uid, timeoutSeconds=timeoutSeconds
+ )
</ins><span class="cx">
</span><span class="cx">
</span><del>- def recordWithGUID(self, guid):
- return self._oneFromSubServices("recordWithGUID", guid)
</del><ins>+ def recordWithGUID(self, guid, timeoutSeconds=None):
+ return self._oneFromSubServices(
+ "recordWithGUID", guid, timeoutSeconds=timeoutSeconds
+ )
</ins><span class="cx">
</span><span class="cx">
</span><del>- def recordsWithRecordType(self, recordType):
</del><ins>+ def recordsWithRecordType(
+ self, recordType, limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> # Since we know the recordType, we can go directly to the appropriate
</span><span class="cx"> # service.
</span><span class="cx"> for service in self.services:
</span><span class="cx"> if recordType in service.recordTypes():
</span><del>- return service.recordsWithRecordType(recordType)
</del><ins>+ return service.recordsWithRecordType(
+ recordType,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
+ )
</ins><span class="cx"> return succeed(())
</span><span class="cx">
</span><span class="cx">
</span><del>- def recordWithShortName(self, recordType, shortName):
</del><ins>+ def recordWithShortName(self, recordType, shortName, timeoutSeconds=None):
</ins><span class="cx"> # Since we know the recordType, we can go directly to the appropriate
</span><span class="cx"> # service.
</span><span class="cx"> for service in self.services:
</span><span class="cx"> if recordType in service.recordTypes():
</span><del>- return service.recordWithShortName(recordType, shortName)
</del><ins>+ return service.recordWithShortName(
+ recordType, shortName, timeoutSeconds=timeoutSeconds
+ )
</ins><span class="cx"> return succeed(None)
</span><span class="cx">
</span><span class="cx">
</span><del>- def recordsWithEmailAddress(self, emailAddress):
</del><ins>+ def recordsWithEmailAddress(
+ self, emailAddress, limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> return self._gatherFromSubServices(
</span><del>- "recordsWithEmailAddress", emailAddress
</del><ins>+ "recordsWithEmailAddress", emailAddress,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span></span></pre></div>
<a id="twexttrunktwextwhodirectorypy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/directory.py (13947 => 13948)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/directory.py        2014-09-10 14:52:49 UTC (rev 13947)
+++ twext/trunk/twext/who/directory.py        2014-09-11 03:32:22 UTC (rev 13948)
</span><span class="lines">@@ -123,7 +123,8 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def recordsFromNonCompoundExpression(
</span><del>- self, expression, recordTypes=None, records=None
</del><ins>+ self, expression, recordTypes=None, records=None,
+ limitResults=None, timeoutSeconds=None
</ins><span class="cx"> ):
</span><span class="cx"> """
</span><span class="cx"> Finds records matching a non-compound expression.
</span><span class="lines">@@ -172,7 +173,8 @@
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def recordsFromCompoundExpression(
</span><del>- self, expression, recordTypes=None, records=None
</del><ins>+ self, expression, recordTypes=None, records=None,
+ limitResults=None, timeoutSeconds=None
</ins><span class="cx"> ):
</span><span class="cx"> """
</span><span class="cx"> Finds records matching a compound expression.
</span><span class="lines">@@ -246,7 +248,10 @@
</span><span class="cx"> returnValue(results)
</span><span class="cx">
</span><span class="cx">
</span><del>- def recordsFromExpression(self, expression, recordTypes=None, records=None):
</del><ins>+ def recordsFromExpression(
+ self, expression, recordTypes=None, records=None,
+ limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> """
</span><span class="cx"> @note: This interface is the same as
</span><span class="cx"> L{IDirectoryService.recordsFromExpression}, except for the
</span><span class="lines">@@ -254,41 +259,57 @@
</span><span class="cx"> """
</span><span class="cx"> if isinstance(expression, CompoundExpression):
</span><span class="cx"> return self.recordsFromCompoundExpression(
</span><del>- expression, recordTypes=recordTypes
</del><ins>+ expression, recordTypes=recordTypes,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx"> else:
</span><span class="cx"> return self.recordsFromNonCompoundExpression(
</span><del>- expression, recordTypes=recordTypes
</del><ins>+ expression, recordTypes=recordTypes,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><del>- def recordsWithFieldValue(self, fieldName, value, recordTypes=None):
</del><ins>+ def recordsWithFieldValue(
+ self, fieldName, value, recordTypes=None,
+ limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> return self.recordsFromExpression(
</span><span class="cx"> MatchExpression(fieldName, value),
</span><del>- recordTypes=recordTypes
</del><ins>+ recordTypes=recordTypes,
+ limitResults=limitResults,
+ timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def recordWithUID(self, uid):
</del><ins>+ def recordWithUID(self, uid, timeoutSeconds=None):
</ins><span class="cx"> returnValue(uniqueResult(
</span><del>- (yield self.recordsWithFieldValue(FieldName.uid, uid))
</del><ins>+ (yield self.recordsWithFieldValue(
+ FieldName.uid, uid, timeoutSeconds=timeoutSeconds
+ ))
</ins><span class="cx"> ))
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def recordWithGUID(self, guid):
</del><ins>+ def recordWithGUID(self, guid, timeoutSeconds=None):
</ins><span class="cx"> returnValue(uniqueResult(
</span><del>- (yield self.recordsWithFieldValue(FieldName.guid, guid))
</del><ins>+ (yield self.recordsWithFieldValue(
+ FieldName.guid, guid, timeoutSeconds=timeoutSeconds
+ ))
</ins><span class="cx"> ))
</span><span class="cx">
</span><span class="cx">
</span><del>- def recordsWithRecordType(self, recordType):
- return self.recordsWithFieldValue(FieldName.recordType, recordType)
</del><ins>+ def recordsWithRecordType(
+ self, recordType, limitResults=None, timeoutSeconds=None
+ ):
+ return self.recordsWithFieldValue(
+ FieldName.recordType, recordType,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
+ )
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def recordWithShortName(self, recordType, shortName):
</del><ins>+ def recordWithShortName(self, recordType, shortName, timeoutSeconds=None):
</ins><span class="cx"> returnValue(
</span><span class="cx"> uniqueResult(
</span><span class="cx"> (
</span><span class="lines">@@ -296,17 +317,22 @@
</span><span class="cx"> MatchExpression(
</span><span class="cx"> FieldName.shortNames, shortName
</span><span class="cx"> ),
</span><del>- recordTypes=[recordType]
</del><ins>+ recordTypes=[recordType],
+ timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx"> )
</span><span class="cx"> )
</span><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><del>- def recordsWithEmailAddress(self, emailAddress):
</del><ins>+ def recordsWithEmailAddress(
+ self, emailAddress, limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> return self.recordsWithFieldValue(
</span><span class="cx"> FieldName.emailAddresses,
</span><span class="cx"> emailAddress,
</span><ins>+ limitResults=limitResults,
+ timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span></span></pre></div>
<a id="twexttrunktwextwhoidirectorypy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/idirectory.py (13947 => 13948)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/idirectory.py        2014-09-10 14:52:49 UTC (rev 13947)
+++ twext/trunk/twext/who/idirectory.py        2014-09-11 03:32:22 UTC (rev 13948)
</span><span class="lines">@@ -277,7 +277,9 @@
</span><span class="cx"> @rtype: iterable of L{NamedConstant}s
</span><span class="cx"> """
</span><span class="cx">
</span><del>- def recordsFromExpression(expression, recordTypes=None):
</del><ins>+ def recordsFromExpression(
+ expression, recordTypes=None, limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> """
</span><span class="cx"> Find records matching an expression.
</span><span class="cx">
</span><span class="lines">@@ -288,6 +290,13 @@
</span><span class="cx"> @type recordTypes: an iterable of L{NamedConstant}, or None for no
</span><span class="cx"> filtering
</span><span class="cx">
</span><ins>+ @param limitResults: how many records to limit the results to
+ @type limitResults: an C{integer} or None if no limit desired
+
+ @param timeoutSeconds: how long (in seconds) to let a directory service
+ request to run before giving up
+ @type timeoutSeconds: an C{integer} or None if no limit desired
+
</ins><span class="cx"> @return: The matching records.
</span><span class="cx"> @rtype: deferred iterable of L{IDirectoryRecord}s
</span><span class="cx">
</span><span class="lines">@@ -295,7 +304,9 @@
</span><span class="cx"> supported by this directory service.
</span><span class="cx"> """
</span><span class="cx">
</span><del>- def recordsWithFieldValue(fieldName, value):
</del><ins>+ def recordsWithFieldValue(
+ fieldName, value, limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> """
</span><span class="cx"> Find records that have the given field name with the given
</span><span class="cx"> value.
</span><span class="lines">@@ -306,44 +317,68 @@
</span><span class="cx"> @param value: a value to match
</span><span class="cx"> @type value: L{object}
</span><span class="cx">
</span><ins>+ @param limitResults: how many records to limit the results to
+ @type limitResults: an C{integer} or None if no limit desired
+
+ @param timeoutSeconds: how long (in seconds) to let a directory service
+ request to run before giving up
+ @type timeoutSeconds: an C{integer} or None if no limit desired
+
</ins><span class="cx"> @return: The matching records.
</span><span class="cx"> @rtype: deferred iterable of L{IDirectoryRecord}s
</span><span class="cx"> """
</span><span class="cx">
</span><del>- def recordWithUID(uid):
</del><ins>+ def recordWithUID(uid, timeoutSeconds=None):
</ins><span class="cx"> """
</span><span class="cx"> Find the record that has the given UID.
</span><span class="cx">
</span><span class="cx"> @param uid: a UID
</span><span class="cx"> @type uid: L{unicode}
</span><span class="cx">
</span><ins>+ @param timeoutSeconds: how long (in seconds) to let a directory service
+ request to run before giving up
+ @type timeoutSeconds: an C{integer} or None if no limit desired
+
</ins><span class="cx"> @return: The matching record or C{None} if there is no match.
</span><span class="cx"> @rtype: deferred L{IDirectoryRecord}s or C{None}
</span><span class="cx"> """
</span><span class="cx">
</span><del>- def recordWithGUID(guid):
</del><ins>+ def recordWithGUID(guid, timeoutSeconds=None):
</ins><span class="cx"> """
</span><span class="cx"> Find the record that has the given GUID.
</span><span class="cx">
</span><span class="cx"> @param guid: a GUID
</span><span class="cx"> @type guid: L{UUID}
</span><span class="cx">
</span><ins>+ @param timeoutSeconds: how long (in seconds) to let a directory service
+ request to run before giving up
+ @type timeoutSeconds: an C{integer} or None if no limit desired
+
</ins><span class="cx"> @return: The matching record or C{None} if there is no match.
</span><span class="cx"> @rtype: deferred L{IDirectoryRecord}s or C{None}
</span><span class="cx"> """
</span><span class="cx">
</span><del>- def recordsWithRecordType(recordType):
</del><ins>+ def recordsWithRecordType(
+ recordType, limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> """
</span><span class="cx"> Find the records that have the given record type.
</span><span class="cx">
</span><span class="cx"> @param recordType: a record type
</span><span class="cx"> @type recordType: L{NamedConstant}
</span><span class="cx">
</span><ins>+ @param limitResults: how many records to limit the results to
+ @type limitResults: an C{integer} or None if no limit desired
+
+ @param timeoutSeconds: how long (in seconds) to let a directory service
+ request to run before giving up
+ @type timeoutSeconds: an C{integer} or None if no limit desired
+
</ins><span class="cx"> @return: The matching records.
</span><span class="cx"> @rtype: deferred iterable of L{IDirectoryRecord}s
</span><span class="cx"> """
</span><span class="cx">
</span><del>- def recordWithShortName(recordType, shortName):
</del><ins>+ def recordWithShortName(recordType, shortName, timeoutSeconds=None):
</ins><span class="cx"> """
</span><span class="cx"> Find the record that has the given record type and short name.
</span><span class="cx">
</span><span class="lines">@@ -353,17 +388,27 @@
</span><span class="cx"> @param shortName: a short name
</span><span class="cx"> @type shortName: L{unicode}
</span><span class="cx">
</span><ins>+ @param timeoutSeconds: how long (in seconds) to let a directory service
+ request to run before giving up
+ @type timeoutSeconds: an C{integer} or None if no limit desired
+
</ins><span class="cx"> @return: The matching record or C{None} if there is no match.
</span><span class="cx"> @rtype: deferred L{IDirectoryRecord}s or C{None}
</span><span class="cx"> """
</span><span class="cx">
</span><del>- def recordsWithEmailAddress(emailAddress):
</del><ins>+ def recordsWithEmailAddress(
+ emailAddress, limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> """
</span><span class="cx"> Find the records that have the given email address.
</span><span class="cx">
</span><span class="cx"> @param emailAddress: an email address
</span><span class="cx"> @type emailAddress: L{unicode}
</span><span class="cx">
</span><ins>+ @param timeoutSeconds: how long (in seconds) to let a directory service
+ request to run before giving up
+ @type timeoutSeconds: an C{integer} or None if no limit desired
+
</ins><span class="cx"> @return: The matching records.
</span><span class="cx"> @rtype: deferred iterable of L{IDirectoryRecord}s
</span><span class="cx"> """
</span></span></pre></div>
<a id="twexttrunktwextwhoindexpy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/index.py (13947 => 13948)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/index.py        2014-09-10 14:52:49 UTC (rev 13947)
+++ twext/trunk/twext/who/index.py        2014-09-11 03:32:22 UTC (rev 13948)
</span><span class="lines">@@ -227,7 +227,8 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def indexedRecordsFromMatchExpression(
</span><del>- self, expression, recordTypes=None, records=None
</del><ins>+ self, expression, recordTypes=None, records=None,
+ limitResults=None, timeoutSeconds=None
</ins><span class="cx"> ):
</span><span class="cx"> """
</span><span class="cx"> Finds records in the internal indexes matching a single expression.
</span><span class="lines">@@ -293,11 +294,15 @@
</span><span class="cx"> if record.recordType not in recordTypes:
</span><span class="cx"> matchingRecords.remove(record)
</span><span class="cx">
</span><ins>+ if limitResults is not None:
+ matchingRecords = set(list(matchingRecords)[:limitResults])
+
</ins><span class="cx"> return succeed(matchingRecords)
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def unIndexedRecordsFromMatchExpression(
</span><del>- self, expression, recordTypes=None, records=None
</del><ins>+ self, expression, recordTypes=None, records=None,
+ limitResults=None, timeoutSeconds=None
</ins><span class="cx"> ):
</span><span class="cx"> """
</span><span class="cx"> Finds records not in the internal indexes matching a single expression.
</span><span class="lines">@@ -335,11 +340,15 @@
</span><span class="cx"> if expression.match(fieldValue):
</span><span class="cx"> result.add(record)
</span><span class="cx">
</span><ins>+ if limitResults is not None:
+ result = set(list(result)[:limitResults])
+
</ins><span class="cx"> return succeed(result)
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def recordsFromNonCompoundExpression(
</span><del>- self, expression, recordTypes=None, records=None
</del><ins>+ self, expression, recordTypes=None, records=None,
+ limitResults=None, timeoutSeconds=None
</ins><span class="cx"> ):
</span><span class="cx"> """
</span><span class="cx"> This implementation can handle L{MatchExpression} expressions; other
</span><span class="lines">@@ -348,15 +357,18 @@
</span><span class="cx"> if isinstance(expression, MatchExpression):
</span><span class="cx"> if expression.fieldName in self.indexedFields:
</span><span class="cx"> return self.indexedRecordsFromMatchExpression(
</span><del>- expression, recordTypes=recordTypes, records=records
</del><ins>+ expression, recordTypes=recordTypes, records=records,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx"> else:
</span><span class="cx"> return self.unIndexedRecordsFromMatchExpression(
</span><del>- expression, recordTypes=recordTypes, records=records
</del><ins>+ expression, recordTypes=recordTypes, records=records,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx"> else:
</span><span class="cx"> return BaseDirectoryService.recordsFromNonCompoundExpression(
</span><del>- self, expression, recordTypes=recordTypes, records=records
</del><ins>+ self, expression, recordTypes=recordTypes, records=records,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span></span></pre></div>
<a id="twexttrunktwextwholdap_servicepy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/ldap/_service.py (13947 => 13948)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/ldap/_service.py        2014-09-10 14:52:49 UTC (rev 13947)
+++ twext/trunk/twext/who/ldap/_service.py        2014-09-11 03:32:22 UTC (rev 13948)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx">
</span><span class="cx"> import collections
</span><span class="cx"> import ldap
</span><ins>+import ldap.async
</ins><span class="cx">
</span><span class="cx"> from twisted.python.constants import Names, NamedConstant
</span><span class="cx"> from twisted.internet.defer import succeed, inlineCallbacks, returnValue
</span><span class="lines">@@ -47,7 +48,10 @@
</span><span class="cx"> DirectoryService as BaseDirectoryService,
</span><span class="cx"> DirectoryRecord as BaseDirectoryRecord,
</span><span class="cx"> )
</span><del>-from ..expression import MatchExpression, ExistsExpression, BooleanExpression
</del><ins>+from ..expression import (
+ MatchExpression, ExistsExpression, BooleanExpression,
+ CompoundExpression, Operand, MatchType
+)
</ins><span class="cx"> from ..util import ConstantsContainer
</span><span class="cx"> from ._constants import LDAPAttribute, LDAPObjectClass
</span><span class="cx"> from ._util import (
</span><span class="lines">@@ -554,16 +558,24 @@
</span><span class="cx"> connection = None
</span><span class="cx">
</span><span class="cx">
</span><del>- def _recordsFromQueryString(self, queryString, recordTypes=None):
</del><ins>+ def _recordsFromQueryString(
+ self, queryString, recordTypes=None,
+ limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> return deferToThreadPool(
</span><span class="cx"> reactor, self.threadpool,
</span><span class="cx"> self._recordsFromQueryString_inThread,
</span><span class="cx"> queryString,
</span><span class="cx"> recordTypes,
</span><ins>+ limitResults=limitResults,
+ timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><del>- def _recordsFromQueryString_inThread(self, queryString, recordTypes=None):
</del><ins>+ def _recordsFromQueryString_inThread(
+ self, queryString, recordTypes=None,
+ limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> """
</span><span class="cx"> This method is always called in a thread.
</span><span class="cx"> """
</span><span class="lines">@@ -571,10 +583,16 @@
</span><span class="cx">
</span><span class="cx"> with DirectoryService.Connection(self) as connection:
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> if recordTypes is None:
</span><span class="cx"> recordTypes = self.recordTypes()
</span><span class="cx">
</span><span class="cx"> for recordType in recordTypes:
</span><ins>+
+ if limitResults is not None:
+ if limitResults < 1:
+ break
+
</ins><span class="cx"> try:
</span><span class="cx"> rdn = self._recordTypeSchemas[recordType].relativeDN
</span><span class="cx"> except KeyError:
</span><span class="lines">@@ -586,23 +604,35 @@
</span><span class="cx"> ldap.dn.str2dn(self._baseDN.lower())
</span><span class="cx"> )
</span><span class="cx"> self.log.debug(
</span><del>- "Performing LDAP query: {rdn} {query} {recordType}",
</del><ins>+ "Performing LDAP query: {rdn} {query} {recordType}{limit}{timeout}",
</ins><span class="cx"> rdn=rdn,
</span><span class="cx"> query=queryString,
</span><del>- recordType=recordType
</del><ins>+ recordType=recordType,
+ limit=" limit={}".format(limitResults) if limitResults else "",
+ timeout=" timeout={}".format(timeoutSeconds) if timeoutSeconds else "",
</ins><span class="cx"> )
</span><span class="cx"> try:
</span><del>- reply = connection.search_s(
</del><ins>+ s = ldap.async.List(connection)
+ s.startSearch(
</ins><span class="cx"> ldap.dn.dn2str(rdn),
</span><span class="cx"> ldap.SCOPE_SUBTREE,
</span><span class="cx"> queryString,
</span><del>- attrlist=self._attributesToFetch
</del><ins>+ attrList=self._attributesToFetch,
+ timeout=timeoutSeconds if timeoutSeconds else -1,
+ sizelimit=limitResults if limitResults else 0
</ins><span class="cx"> )
</span><ins>+ s.processResults()
</ins><span class="cx">
</span><ins>+ except ldap.SIZELIMIT_EXCEEDED, e:
+ self.log.debug("LDAP result limit exceeded: {}".format(limitResults,))
+
+ except ldap.TIMELIMIT_EXCEEDED, e:
+ self.log.warn("LDAP timeout exceeded: {} seconds".format(timeoutSeconds,))
+
</ins><span class="cx"> except ldap.FILTER_ERROR as e:
</span><span class="cx"> self.log.error(
</span><del>- "Unable to perform query {0!r}: {1}"
- .format(queryString, e)
</del><ins>+ "Unable to perform query {query!r}: {err}",
+ query=queryString, err=e
</ins><span class="cx"> )
</span><span class="cx"> raise LDAPQueryError("Unable to perform query", e)
</span><span class="cx">
</span><span class="lines">@@ -610,10 +640,49 @@
</span><span class="cx"> # self.log.warn("RDN {rdn} does not exist, skipping", rdn=rdn)
</span><span class="cx"> continue
</span><span class="cx">
</span><del>- records.extend(
- self._recordsFromReply(reply, recordType=recordType)
</del><ins>+ except ldap.INVALID_SYNTAX, e:
+ self.log.error(
+ "LDAP invalid syntax {query!r}: {err}",
+ query=queryString, err=e
+ )
+ continue
+
+ except ldap.SERVER_DOWN:
+ self.log.error(
+ "LDAP server unavailable"
+ )
+ continue
+
+ except Exception, e:
+ self.log.error(
+ "LDAP error {query!r}: {err}",
+ query=queryString, err=e
+ )
+ continue
+
+ reply = [resultItem for resultType, resultItem in s.allResults]
+
+ newRecords = self._recordsFromReply(reply, recordType=recordType)
+
+ self.log.debug(
+ "Records from LDAP query ({rdn} {query} {recordType}): {count}",
+ rdn=rdn,
+ query=queryString,
+ recordType=recordType,
+ count=len(newRecords)
</ins><span class="cx"> )
</span><span class="cx">
</span><ins>+ if limitResults is not None:
+ limitResults = limitResults - len(newRecords)
+
+ records.extend(newRecords)
+
+ self.log.debug(
+ "LDAP result count ({query}): {count}",
+ query=queryString,
+ count=len(records)
+ )
+
</ins><span class="cx"> return records
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -758,7 +827,8 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def recordsFromNonCompoundExpression(
</span><del>- self, expression, recordTypes=None, records=None
</del><ins>+ self, expression, recordTypes=None, records=None, limitResults=None,
+ timeoutSeconds=None
</ins><span class="cx"> ):
</span><span class="cx"> if isinstance(expression, MatchExpression):
</span><span class="cx"> queryString = ldapQueryStringFromMatchExpression(
</span><span class="lines">@@ -766,7 +836,8 @@
</span><span class="cx"> self._fieldNameToAttributesMap, self._recordTypeSchemas
</span><span class="cx"> )
</span><span class="cx"> return self._recordsFromQueryString(
</span><del>- queryString, recordTypes=recordTypes
</del><ins>+ queryString, recordTypes=recordTypes,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx"> elif isinstance(expression, ExistsExpression):
</span><span class="lines">@@ -775,7 +846,8 @@
</span><span class="cx"> self._fieldNameToAttributesMap, self._recordTypeSchemas
</span><span class="cx"> )
</span><span class="cx"> return self._recordsFromQueryString(
</span><del>- queryString, recordTypes=recordTypes
</del><ins>+ queryString, recordTypes=recordTypes,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx"> elif isinstance(expression, BooleanExpression):
</span><span class="lines">@@ -784,16 +856,19 @@
</span><span class="cx"> self._fieldNameToAttributesMap, self._recordTypeSchemas
</span><span class="cx"> )
</span><span class="cx"> return self._recordsFromQueryString(
</span><del>- queryString, recordTypes=recordTypes
</del><ins>+ queryString, recordTypes=recordTypes,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx"> return BaseDirectoryService.recordsFromNonCompoundExpression(
</span><del>- self, expression, records=records
</del><ins>+ self, expression, records=records, limitResults=limitResults,
+ timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def recordsFromCompoundExpression(
</span><del>- self, expression, recordTypes=None, records=None
</del><ins>+ self, expression, recordTypes=None, records=None,
+ limitResults=None, timeoutSeconds=None
</ins><span class="cx"> ):
</span><span class="cx"> if not expression.expressions:
</span><span class="cx"> return succeed(())
</span><span class="lines">@@ -803,17 +878,21 @@
</span><span class="cx"> self._fieldNameToAttributesMap, self._recordTypeSchemas
</span><span class="cx"> )
</span><span class="cx"> return self._recordsFromQueryString(
</span><del>- queryString, recordTypes=recordTypes
</del><ins>+ queryString, recordTypes=recordTypes,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><del>- def recordsWithRecordType(self, recordType):
</del><ins>+ def recordsWithRecordType(
+ self, recordType, limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> queryString = ldapQueryStringFromExistsExpression(
</span><span class="cx"> ExistsExpression(self.fieldName.uid),
</span><span class="cx"> self._fieldNameToAttributesMap, self._recordTypeSchemas
</span><span class="cx"> )
</span><span class="cx"> return self._recordsFromQueryString(
</span><del>- queryString, recordTypes=[recordType]
</del><ins>+ queryString, recordTypes=[recordType],
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -839,12 +918,66 @@
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def members(self):
</span><span class="cx">
</span><ins>+ members = set()
+
</ins><span class="cx"> if self.recordType != self.service.recordType.group:
</span><span class="cx"> returnValue(())
</span><span class="cx">
</span><del>- members = set()
- for dn in getattr(self, "memberDNs", []):
- record = yield self.service._recordWithDN(dn)
</del><ins>+ # Scan through the memberDNs, grouping them by record type (which we
+ # deduce by their RDN). If we have a fieldname that corresponds to
+ # the most specific slice of the DN, we can bundle that into a
+ # single CompoundExpression to fault in all the DNs belonging to the
+ # same base RDN, reducing the number of requests from 1-per-member to
+ # 1-per-record-type. Any memberDNs we can't group in this way are
+ # simply faulted in by DN at the end.
+
+ fieldValuesByRecordType = {}
+ # dictionary key = recordType, value = tuple(fieldName, value)
+
+ faultByDN = []
+ # the DNs we need to fault in individually
+
+ for dnStr in getattr(self, "memberDNs", []):
+ try:
+ recordType = recordTypeForDN(
+ self.service._baseDN, self.service._recordTypeSchemas, dnStr
+ )
+ dn = ldap.dn.str2dn(dnStr.lower())
+ attrName, value, ignored = dn[0][0]
+ fieldName = self.service._attributeToFieldNameMap[attrName][0]
+ fieldValuesByRecordType.setdefault(recordType, []).append((fieldName, value))
+ continue
+
+ except:
+ # For whatever reason we can't group this DN in with the others
+ # so we'll add it to faultByDN just below
+ pass
+
+ # have to fault in by dn
+ faultByDN.append(dnStr)
+
+ for recordType, fieldValue in fieldValuesByRecordType.iteritems():
+ if fieldValue:
+ matchExpressions = []
+ for fieldName, value in fieldValue:
+ matchExpressions.append(
+ MatchExpression(
+ fieldName,
+ value.decode("utf-8"),
+ matchType=MatchType.equals
+ )
+ )
+ expression = CompoundExpression(
+ matchExpressions,
+ Operand.OR
+ )
+ for record in (yield self.service.recordsFromCompoundExpression(
+ expression, recordTypes=[recordType]
+ )):
+ members.add(record)
+
+ for dnStr in faultByDN:
+ record = yield self.service._recordWithDN(dnStr)
</ins><span class="cx"> members.add(record)
</span><span class="cx">
</span><span class="cx"> returnValue(members)
</span><span class="lines">@@ -863,6 +996,7 @@
</span><span class="cx"> return self.service._authenticateUsernamePassword(self.dn, password)
</span><span class="cx">
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> def normalizeDNstr(dnStr):
</span><span class="cx"> """
</span><span class="cx"> Convert to lowercase and remove extra whitespace
</span></span></pre></div>
<a id="twexttrunktwextwholdaptesttest_servicepy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/ldap/test/test_service.py (13947 => 13948)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/ldap/test/test_service.py        2014-09-10 14:52:49 UTC (rev 13947)
+++ twext/trunk/twext/who/ldap/test/test_service.py        2014-09-11 03:32:22 UTC (rev 13948)
</span><span class="lines">@@ -24,13 +24,21 @@
</span><span class="cx">
</span><span class="cx"> import ldap
</span><span class="cx">
</span><del>-try:
- from mockldap import MockLdap
- from mockldap.filter import (
- Test as MockLDAPFilterTest,
- UnsupportedOp as MockLDAPUnsupportedOp,
- )
-except ImportError:
</del><ins>+
+# FIXME:
+MOCKLDAP_SUPPORTS_LDAP_ASYNC = False
+
+
+if MOCKLDAP_SUPPORTS_LDAP_ASYNC:
+ try:
+ from mockldap import MockLdap
+ from mockldap.filter import (
+ Test as MockLDAPFilterTest,
+ UnsupportedOp as MockLDAPUnsupportedOp,
+ )
+ except ImportError:
+ MockLdap = None
+else:
</ins><span class="cx"> MockLdap = None
</span><span class="cx">
</span><span class="cx"> from twext.python.types import MappingProxyType
</span></span></pre></div>
<a id="twexttrunktwextwhoopendirectory_servicepy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/opendirectory/_service.py (13947 => 13948)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/opendirectory/_service.py        2014-09-10 14:52:49 UTC (rev 13947)
+++ twext/trunk/twext/who/opendirectory/_service.py        2014-09-11 03:32:22 UTC (rev 13948)
</span><span class="lines">@@ -392,7 +392,9 @@
</span><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><del>- def _queryFromCompoundExpression(self, expression, recordTypes=None, local=False):
</del><ins>+ def _queryFromCompoundExpression(
+ self, expression, recordTypes=None, local=False, limitResults=None
+ ):
</ins><span class="cx"> """
</span><span class="cx"> Form an OpenDirectory query from a compound expression.
</span><span class="cx">
</span><span class="lines">@@ -442,7 +444,10 @@
</span><span class="cx"> matchType = ODMatchType.any.value
</span><span class="cx">
</span><span class="cx"> attributes = [a.value for a in ODAttribute.iterconstants()]
</span><del>- maxResults = 0
</del><ins>+ if limitResults is None:
+ maxResults = 0
+ else:
+ maxResults = limitResults
</ins><span class="cx">
</span><span class="cx"> query, error = ODQuery.queryWithNode_forRecordTypes_attribute_matchType_queryValues_returnAttributes_maximumResults_error_(
</span><span class="cx"> node,
</span><span class="lines">@@ -468,7 +473,7 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def _queryFromMatchExpression(
</span><del>- self, expression, recordTypes=None, local=False
</del><ins>+ self, expression, recordTypes=None, local=False, limitResults=None
</ins><span class="cx"> ):
</span><span class="cx"> """
</span><span class="cx"> Form an OpenDirectory query from a match expression.
</span><span class="lines">@@ -503,8 +508,12 @@
</span><span class="cx"> caseInsensitive = 0x0
</span><span class="cx">
</span><span class="cx"> fetchAttributes = [a.value for a in ODAttribute.iterconstants()]
</span><del>- maxResults = 0
</del><span class="cx">
</span><ins>+ if limitResults is None:
+ maxResults = 0
+ else:
+ maxResults = limitResults
+
</ins><span class="cx"> # For OpenDirectory, use guid for uid:
</span><span class="cx"> if expression.fieldName is self.fieldName.uid:
</span><span class="cx"> expression.fieldName = self.fieldName.guid
</span><span class="lines">@@ -644,13 +653,17 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def _recordsFromQuery(self, query):
</del><ins>+ def _recordsFromQuery(self, query, timeoutSeconds=None):
</ins><span class="cx"> """
</span><span class="cx"> Executes a query and generates directory records from it.
</span><span class="cx">
</span><span class="cx"> @param query: A query.
</span><span class="cx"> @type query: L{ODQuery}
</span><span class="cx">
</span><ins>+ @param timeoutSeconds: number of seconds after which the request
+ should timeout (currently unused)
+ @type timeoutSeconds: C{integer}
+
</ins><span class="cx"> @return: The records produced by executing the query.
</span><span class="cx"> @rtype: list of L{DirectoryRecord}
</span><span class="cx"> """
</span><span class="lines">@@ -707,11 +720,17 @@
</span><span class="cx"> returnValue(result)
</span><span class="cx">
</span><span class="cx">
</span><del>- def recordsFromNonCompoundExpression(self, expression, recordTypes=None, records=None):
</del><ins>+ def recordsFromNonCompoundExpression(
+ self, expression, recordTypes=None, records=None,
+ limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> if isinstance(expression, MatchExpression):
</span><span class="cx"> try:
</span><del>- query = self._queryFromMatchExpression(expression, recordTypes=recordTypes)
- return self._recordsFromQuery(query)
</del><ins>+ query = self._queryFromMatchExpression(
+ expression, recordTypes=recordTypes, limitResults=limitResults)
+ return self._recordsFromQuery(
+ query, timeoutSeconds=timeoutSeconds
+ )
</ins><span class="cx">
</span><span class="cx"> except QueryNotSupportedError:
</span><span class="cx"> pass # Let the superclass try
</span><span class="lines">@@ -720,12 +739,16 @@
</span><span class="cx"> return succeed([])
</span><span class="cx">
</span><span class="cx"> return BaseDirectoryService.recordsFromNonCompoundExpression(
</span><del>- self, expression
</del><ins>+ self, expression,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def recordsFromCompoundExpression(self, expression, recordTypes=None, records=None):
</del><ins>+ def recordsFromCompoundExpression(
+ self, expression, recordTypes=None, records=None,
+ limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> """
</span><span class="cx"> Returns records matching the CompoundExpression. Because the
</span><span class="cx"> local node doesn't perform Compound queries in a case insensitive
</span><span class="lines">@@ -736,13 +759,16 @@
</span><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> try:
</span><del>- query = self._queryFromCompoundExpression(expression, recordTypes=recordTypes)
</del><ins>+ query = self._queryFromCompoundExpression(
+ expression, recordTypes=recordTypes, limitResults=limitResults
+ )
</ins><span class="cx">
</span><span class="cx"> except QueryNotSupportedError:
</span><span class="cx"> returnValue(
</span><span class="cx"> (
</span><span class="cx"> yield BaseDirectoryService.recordsFromCompoundExpression(
</span><del>- self, expression, recordTypes=recordTypes
</del><ins>+ self, expression, recordTypes=recordTypes,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx"> )
</span><span class="cx"> )
</span><span class="lines">@@ -752,7 +778,8 @@
</span><span class="cx"> if self.localNode is not None:
</span><span class="cx">
</span><span class="cx"> localRecords = yield self.localRecordsFromCompoundExpression(
</span><del>- expression, recordTypes=recordTypes
</del><ins>+ expression, recordTypes=recordTypes,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx"> for localRecord in localRecords:
</span><span class="cx"> if localRecord not in results:
</span><span class="lines">@@ -762,7 +789,10 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def localRecordsFromCompoundExpression(self, expression, recordTypes=None):
</del><ins>+ def localRecordsFromCompoundExpression(
+ self, expression, recordTypes=None,
+ limitResults=None, timeoutSeconds=None
+ ):
</ins><span class="cx"> """
</span><span class="cx"> Takes a CompoundExpression, and recursively goes through each
</span><span class="cx"> MatchExpression, passing those specifically to the local node, and
</span><span class="lines">@@ -780,17 +810,22 @@
</span><span class="cx">
</span><span class="cx"> if isinstance(subExpression, CompoundExpression):
</span><span class="cx"> subRecords = yield self.localRecordsFromCompoundExpression(
</span><del>- subExpression, recordTypes=recordTypes
</del><ins>+ subExpression, recordTypes=recordTypes,
+ limitResults=limitResults, timeoutSeconds=timeoutSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx"> elif isinstance(subExpression, MatchExpression):
</span><span class="cx"> try:
</span><span class="cx"> subQuery = self._queryFromMatchExpression(
</span><del>- subExpression, recordTypes=recordTypes, local=True
</del><ins>+ subExpression, recordTypes=recordTypes, local=True,
+ limitResults=limitResults
</ins><span class="cx"> )
</span><span class="cx"> except UnsupportedRecordTypeError:
</span><span class="cx"> continue
</span><del>- subRecords = yield self._recordsFromQuery(subQuery)
</del><ins>+ subRecords = yield self._recordsFromQuery(
+ subQuery,
+ timeoutSeconds=timeoutSeconds
+ )
</ins><span class="cx">
</span><span class="cx"> else:
</span><span class="cx"> raise QueryNotSupportedError(
</span><span class="lines">@@ -841,27 +876,35 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def recordWithUID(self, uid):
</del><ins>+ def recordWithUID(self, uid, timeoutSeconds=None):
</ins><span class="cx"> returnValue(firstResult(
</span><del>- (yield self.recordsWithFieldValue(BaseFieldName.uid, uid))
</del><ins>+ (yield self.recordsWithFieldValue(
+ BaseFieldName.uid, uid, timeoutSeconds=timeoutSeconds
+ ))
</ins><span class="cx"> ))
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def recordWithGUID(self, guid):
</del><ins>+ def recordWithGUID(self, guid, timeoutSeconds=None):
</ins><span class="cx"> returnValue(firstResult(
</span><del>- (yield self.recordsWithFieldValue(BaseFieldName.guid, guid))
</del><ins>+ (yield self.recordsWithFieldValue(
+ BaseFieldName.guid, guid, timeoutSeconds=timeoutSeconds
+ ))
</ins><span class="cx"> ))
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def recordWithShortName(self, recordType, shortName):
</del><ins>+ def recordWithShortName(self, recordType, shortName, timeoutSeconds=None):
</ins><span class="cx"> try:
</span><span class="cx"> query = self._queryFromMatchExpression(
</span><span class="cx"> MatchExpression(self.fieldName.shortNames, shortName),
</span><del>- recordTypes=(recordType,)
</del><ins>+ recordTypes=(recordType,),
+ limitResults=1
</ins><span class="cx"> )
</span><del>- results = yield self._recordsFromQuery(query)
</del><ins>+ results = yield self._recordsFromQuery(
+ query,
+ timeoutSeconds=timeoutSeconds
+ )
</ins><span class="cx">
</span><span class="cx"> try:
</span><span class="cx"> record = firstResult(results)
</span><span class="lines">@@ -877,7 +920,7 @@
</span><span class="cx"> except QueryNotSupportedError:
</span><span class="cx"> # Let the superclass try
</span><span class="cx"> returnValue((yield BaseDirectoryService.recordWithShortName(
</span><del>- self, recordType, shortName)))
</del><ins>+ self, recordType, shortName, timeoutSeconds=timeoutSeconds)))
</ins><span class="cx">
</span><span class="cx"> except UnsupportedRecordTypeError:
</span><span class="cx"> returnValue(None)
</span></span></pre></div>
<a id="twexttrunktwextwhotesttest_directorypy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/test/test_directory.py (13947 => 13948)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/test/test_directory.py        2014-09-10 14:52:49 UTC (rev 13947)
+++ twext/trunk/twext/who/test/test_directory.py        2014-09-11 03:32:22 UTC (rev 13948)
</span><span class="lines">@@ -71,7 +71,8 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def recordsFromNonCompoundExpression(
</span><del>- self, expression, recordTypes=None, records=None
</del><ins>+ self, expression, recordTypes=None, records=None,
+ limitResults=None, timeoutSeconds=None
</ins><span class="cx"> ):
</span><span class="cx"> """
</span><span class="cx"> This implementation handles three expressions:
</span></span></pre></div>
<a id="twexttrunktwextwhotesttest_indexpy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/test/test_index.py (13947 => 13948)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/test/test_index.py        2014-09-10 14:52:49 UTC (rev 13947)
+++ twext/trunk/twext/who/test/test_index.py        2014-09-11 03:32:22 UTC (rev 13948)
</span><span class="lines">@@ -351,6 +351,34 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><ins>+ def test_unIndexedRecordsFromMatchExpression_limitResults(self):
+ """
+ Make sure limitResults does limit results.
+ """
+ service = self.noLoadServicePopulated()
+
+ records = yield service.unIndexedRecordsFromMatchExpression(
+ MatchExpression(
+ BaseFieldName.fullNames, u"A",
+ MatchType.startsWith
+ ),
+ recordTypes=None,
+ limitResults=1
+ )
+ self.assertEquals(len(records), 1)
+
+ records = yield service.unIndexedRecordsFromMatchExpression(
+ MatchExpression(
+ BaseFieldName.fullNames, u"A",
+ MatchType.startsWith
+ ),
+ recordTypes=None,
+ limitResults=1000
+ )
+ self.assertEquals(len(records), 2)
+
+
+ @inlineCallbacks
</ins><span class="cx"> def _test_recordsFromNonCompoundExpression(self, expression):
</span><span class="cx"> service = self.noLoadServicePopulated()
</span><span class="cx"> yield service.recordsFromNonCompoundExpression(expression)
</span></span></pre></div>
<a id="twexttrunktwextwhotesttest_xmlpy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/test/test_xml.py (13947 => 13948)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/test/test_xml.py        2014-09-10 14:52:49 UTC (rev 13947)
+++ twext/trunk/twext/who/test/test_xml.py        2014-09-11 03:32:22 UTC (rev 13948)
</span><span class="lines">@@ -185,7 +185,32 @@
</span><span class="cx"> self.assertRecords(records, (u"__sagen__", u"__dre__"))
</span><span class="cx">
</span><span class="cx">
</span><ins>+ @inlineCallbacks
+ def test_limitResults(self):
+ """
+ Make sure limitResults does limit results.
+ """
</ins><span class="cx">
</span><ins>+ service = self.service()
+
+ records = (
+ yield service.recordsWithRecordType(
+ service.recordType.user,
+ limitResults=3
+ )
+ )
+ self.assertEquals(len(records), 3)
+
+ records = (
+ yield service.recordsWithRecordType(
+ service.recordType.user,
+ limitResults=1000
+ )
+ )
+ self.assertEquals(len(records), 9)
+
+
+
</ins><span class="cx"> class DirectoryServiceRealmTestMixIn(object):
</span><span class="cx"> def test_realmNameImmutable(self):
</span><span class="cx"> def setRealmName():
</span></span></pre>
</div>
</div>
</body>
</html>