<!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>[12133] 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/12133">12133</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2013-12-18 17:23:27 -0800 (Wed, 18 Dec 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>directory.DirectoryService now has an empty set of supported record types; subclasses must declare all supported record types explicitly.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#twexttrunktwextwhodirectorypy">twext/trunk/twext/who/directory.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>
<li><a href="#twexttrunktwextwhoxmlpy">twext/trunk/twext/who/xml.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="twexttrunktwextwhodirectorypy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/directory.py (12132 => 12133)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/directory.py        2013-12-19 01:14:42 UTC (rev 12132)
+++ twext/trunk/twext/who/directory.py        2013-12-19 01:23:27 UTC (rev 12133)
</span><span class="lines">@@ -35,7 +35,7 @@
</span><span class="cx">     IDirectoryService, IDirectoryRecord,
</span><span class="cx"> )
</span><span class="cx"> from .expression import CompoundExpression, Operand, MatchExpression
</span><del>-from .util import uniqueResult, describe
</del><ins>+from .util import uniqueResult, describe, ConstantsContainer
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -87,7 +87,7 @@
</span><span class="cx">         a L{unicode}).
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-    recordType = RecordType
</del><ins>+    recordType = ConstantsContainer(())
</ins><span class="cx">     fieldName = FieldName
</span><span class="cx"> 
</span><span class="cx">     normalizedFields = {
</span><span class="lines">@@ -302,9 +302,9 @@
</span><span class="cx">             service.recordType.iterconstants()
</span><span class="cx">         ):
</span><span class="cx">             raise ValueError(
</span><del>-                &quot;Record type must be one of {0!r}, not {1!r}.&quot;.format(
</del><ins>+                &quot;Unknown record type: {0!r} is not in {1!r}.&quot;.format(
+                    fields[FieldName.recordType],
</ins><span class="cx">                     tuple(service.recordType.iterconstants()),
</span><del>-                    fields[FieldName.recordType],
</del><span class="cx">                 )
</span><span class="cx">             )
</span><span class="cx"> 
</span></span></pre></div>
<a id="twexttrunktwextwhotesttest_directorypy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/test/test_directory.py (12132 => 12133)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/test/test_directory.py        2013-12-19 01:14:42 UTC (rev 12132)
+++ twext/trunk/twext/who/test/test_directory.py        2013-12-19 01:23:27 UTC (rev 12133)
</span><span class="lines">@@ -35,17 +35,23 @@
</span><span class="cx"> )
</span><span class="cx"> from ..expression import CompoundExpression, Operand
</span><span class="cx"> from ..directory import DirectoryService, DirectoryRecord
</span><ins>+from ..util import ConstantsContainer
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class StubDirectoryService(DirectoryService):
</del><ins>+class TestDirectoryService(DirectoryService):
+    recordType = ConstantsContainer((RecordType,))
+
+
+
+class StubDirectoryService(TestDirectoryService):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Stub directory service with some built-in records and an implementation
</span><span class="cx">     of C{recordsFromNonCompoundExpression}.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">     def __init__(self, realmName):
</span><del>-        DirectoryService.__init__(self, realmName)
</del><ins>+        super(StubDirectoryService, self).__init__(realmName)
</ins><span class="cx"> 
</span><span class="cx">         self.records = RecordStorage(self, DirectoryRecord)
</span><span class="cx"> 
</span><span class="lines">@@ -53,7 +59,10 @@
</span><span class="cx">     def recordsFromExpression(self, expression):
</span><span class="cx">         self.seenExpressions = []
</span><span class="cx"> 
</span><del>-        return DirectoryService.recordsFromExpression(self, expression)
</del><ins>+        return (
+            super(StubDirectoryService, self)
+            .recordsFromExpression(expression)
+        )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def recordsFromNonCompoundExpression(self, expression, records=None):
</span><span class="lines">@@ -80,8 +89,9 @@
</span><span class="cx">                         break
</span><span class="cx">             return succeed(result)
</span><span class="cx"> 
</span><del>-        return DirectoryService.recordsFromNonCompoundExpression(
-            self, expression, records=records
</del><ins>+        return (
+            super(StubDirectoryService, self)
+            .recordsFromNonCompoundExpression(expression, records=records)
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -103,7 +113,7 @@
</span><span class="cx"> 
</span><span class="cx"> class BaseDirectoryServiceTest(ServiceMixIn):
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    Tests for directory services.
</del><ins>+    Tests for L{DirectoryService} and subclasses.
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">     def test_interface(self):
</span><span class="lines">@@ -260,15 +270,16 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class DirectoryServiceRecordsFromExpressionTest(
</span><del>-    unittest.TestCase,
-    ServiceMixIn
</del><ins>+    unittest.TestCase, ServiceMixIn
</ins><span class="cx"> ):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Tests for L{DirectoryService.recordsFromExpression}.
</span><span class="cx">     &quot;&quot;&quot;
</span><ins>+
</ins><span class="cx">     serviceClass = StubDirectoryService
</span><span class="cx">     directoryRecordClass = DirectoryRecord
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx">     @inlineCallbacks
</span><span class="cx">     def test_recordsFromExpression_single(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -402,13 +413,13 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class DirectoryServiceConvenienceTest(
</span><del>-    unittest.TestCase,
-    BaseDirectoryServiceTest
</del><ins>+    unittest.TestCase, BaseDirectoryServiceTest
</ins><span class="cx"> ):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Tests for L{DirectoryService} convenience methods.
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    serviceClass = DirectoryService
</del><ins>+
+    serviceClass = TestDirectoryService
</ins><span class="cx">     directoryRecordClass = DirectoryRecord
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -520,13 +531,13 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class DirectoryServiceImmutableTest(
</span><del>-    unittest.TestCase,
-    BaseDirectoryServiceImmutableTest,
</del><ins>+    unittest.TestCase, BaseDirectoryServiceImmutableTest,
</ins><span class="cx"> ):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Tests for immutable L{DirectoryService}.
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    serviceClass = DirectoryService
</del><ins>+
+    serviceClass = TestDirectoryService
</ins><span class="cx">     directoryRecordClass = DirectoryRecord
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -598,7 +609,7 @@
</span><span class="cx">             fields = self.fields_wsanchez
</span><span class="cx">         if service is None:
</span><span class="cx">             service = self.service()
</span><del>-        return DirectoryRecord(service, fields)
</del><ins>+        return self.directoryRecordClass(service, fields)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_interface(self):
</span><span class="lines">@@ -710,7 +721,7 @@
</span><span class="cx">         fields_glyphmod = self.fields_glyph.copy()
</span><span class="cx">         del fields_glyphmod[FieldName.emailAddresses]
</span><span class="cx"> 
</span><del>-        plugh = DirectoryService(u&quot;plugh&quot;)
</del><ins>+        plugh = self.serviceClass(u&quot;plugh&quot;)
</ins><span class="cx"> 
</span><span class="cx">         wsanchez    = self.makeRecord(self.fields_wsanchez)
</span><span class="cx">         wsanchezmod = self.makeRecord(self.fields_wsanchez, plugh)
</span><span class="lines">@@ -809,9 +820,11 @@
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Tests for L{DirectoryRecord}.
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    serviceClass = DirectoryService
</del><ins>+
+    serviceClass = TestDirectoryService
</ins><span class="cx">     directoryRecordClass = DirectoryRecord
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx">     def test_members_group(self):
</span><span class="cx">         staff = self.makeRecord(self.fields_staff)
</span><span class="cx"> 
</span><span class="lines">@@ -829,6 +842,7 @@
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Container for directory records.
</span><span class="cx">     &quot;&quot;&quot;
</span><ins>+
</ins><span class="cx">     def __init__(self, service, recordClass):
</span><span class="cx">         self.service = service
</span><span class="cx">         self.recordClass = recordClass
</span><span class="lines">@@ -938,6 +952,7 @@
</span><span class="cx">         service = self.service
</span><span class="cx">         fieldName = service.fieldName
</span><span class="cx">         recordType = service.recordType
</span><ins>+
</ins><span class="cx">         self.records.append(self.recordClass(self.service, {
</span><span class="cx">             fieldName.recordType: recordType.user,
</span><span class="cx">             fieldName.uid: u&quot;__{0}__&quot;.format(shortNames[0]),
</span></span></pre></div>
<a id="twexttrunktwextwhotesttest_indexpy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/test/test_index.py (12132 => 12133)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/test/test_index.py        2013-12-19 01:14:42 UTC (rev 12132)
+++ twext/trunk/twext/who/test/test_index.py        2013-12-19 01:23:27 UTC (rev 12133)
</span><span class="lines">@@ -21,14 +21,23 @@
</span><span class="cx"> from twisted.trial import unittest
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue
</span><span class="cx"> 
</span><del>-from ..idirectory import FieldName as BaseFieldName, QueryNotSupportedError
</del><ins>+from ..idirectory import (
+    FieldName as BaseFieldName, RecordType as BaseRecordType,
+    QueryNotSupportedError,
+)
</ins><span class="cx"> from ..expression import MatchExpression, MatchType
</span><span class="cx"> from ..index import DirectoryService, DirectoryRecord
</span><ins>+from ..util import ConstantsContainer
</ins><span class="cx"> from . import test_directory
</span><span class="cx"> from .test_directory import RecordStorage
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+class TestDirectoryService(DirectoryService):
+    recordType = ConstantsContainer((BaseRecordType,))
+
+
+
</ins><span class="cx"> def noLoadDirectoryService(superClass):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Creates an indexed directory service that has a no-op implementation of
</span><span class="lines">@@ -370,7 +379,8 @@
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Tests for L{DirectoryService}.
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    serviceClass = DirectoryService
</del><ins>+
+    serviceClass = TestDirectoryService
</ins><span class="cx">     directoryRecordClass = DirectoryRecord
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -386,7 +396,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Getting the C{index} property calls C{loadRecords}.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        class TestService(DirectoryService):
</del><ins>+        class TestService(self.serviceClass):
</ins><span class="cx">             loaded = False
</span><span class="cx"> 
</span><span class="cx">             def loadRecords(self):
</span><span class="lines">@@ -434,7 +444,8 @@
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Tests for immutable L{DirectoryService}.
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    serviceClass = DirectoryService
</del><ins>+
+    serviceClass = TestDirectoryService
</ins><span class="cx">     directoryRecordClass = DirectoryRecord
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -450,7 +461,8 @@
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Tests for L{DirectoryRecord}.
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    serviceClass = DirectoryService
</del><ins>+
+    serviceClass = TestDirectoryService
</ins><span class="cx">     directoryRecordClass = DirectoryRecord
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="twexttrunktwextwhotesttest_xmlpy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/test/test_xml.py (12132 => 12133)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/test/test_xml.py        2013-12-19 01:14:42 UTC (rev 12132)
+++ twext/trunk/twext/who/test/test_xml.py        2013-12-19 01:23:27 UTC (rev 12133)
</span><span class="lines">@@ -771,9 +771,11 @@
</span><span class="cx">     BaseTest,
</span><span class="cx">     test_index.BaseDirectoryRecordTest
</span><span class="cx"> ):
</span><ins>+
</ins><span class="cx">     serviceClass = DirectoryService
</span><span class="cx">     directoryRecordClass = DirectoryRecord
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx">     @inlineCallbacks
</span><span class="cx">     def test_members_group(self):
</span><span class="cx">         service = self.service()
</span></span></pre></div>
<a id="twexttrunktwextwhoxmlpy"></a>
<div class="modfile"><h4>Modified: twext/trunk/twext/who/xml.py (12132 => 12133)</h4>
<pre class="diff"><span>
<span class="info">--- twext/trunk/twext/who/xml.py        2013-12-19 01:14:42 UTC (rev 12132)
+++ twext/trunk/twext/who/xml.py        2013-12-19 01:23:27 UTC (rev 12133)
</span><span class="lines">@@ -47,6 +47,7 @@
</span><span class="cx">     DirectoryService as BaseDirectoryService,
</span><span class="cx">     DirectoryRecord, FieldName as IndexFieldName,
</span><span class="cx"> )
</span><ins>+from .util import ConstantsContainer
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -128,6 +129,8 @@
</span><span class="cx">     XML directory service.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><ins>+    recordType = ConstantsContainer((RecordType.user, RecordType.group))
+
</ins><span class="cx">     element   = Element
</span><span class="cx">     attribute = Attribute
</span><span class="cx">     value     = Value
</span></span></pre>
</div>
</div>

</body>
</html>