<!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>[13071] CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/agent.py</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/13071">13071</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2014-03-31 17:27:18 -0700 (Mon, 31 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>lint</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagenmove2who4calendarservertoolsagentpy">CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/agent.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserssagenmove2who4calendarservertoolsagentpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/agent.py (13070 => 13071)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/agent.py        2014-03-31 23:26:45 UTC (rev 13070)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/agent.py        2014-04-01 00:27:18 UTC (rev 13071)
</span><span class="lines">@@ -18,10 +18,10 @@
</span><span class="cx"> 
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> A service spawned on-demand by launchd, meant to handle configuration requests
</span><del>-from Server.app.  When a request comes in on the socket specified in the launchd
-agent.plist, launchd will run &quot;caldavd -t Agent&quot; which ends up creating this
-service.  Requests are made using HTTP POSTS to /gateway, and are authenticated
-by OpenDirectory.
</del><ins>+from Server.app.  When a request comes in on the socket specified in the
+launchd agent.plist, launchd will run &quot;caldavd -t Agent&quot; which ends up creating
+this service.  Requests are made using HTTP POSTS to /gateway, and are
+authenticated by OpenDirectory.
</ins><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx"> from __future__ import print_function
</span><span class="lines">@@ -51,7 +51,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class DirectoryServiceChecker:
</del><ins>+class DirectoryServiceChecker(object):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     A checker that knows how to ask OpenDirectory to authenticate via Digest
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="lines">@@ -64,41 +64,53 @@
</span><span class="cx"> 
</span><span class="cx">     def __init__(self, node):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        @param node: the name of the OpenDirectory node to use, e.g. /Local/Default
</del><ins>+        @param node: the name of the OpenDirectory node to use, e.g.
+            C{&quot;/Local/Default&quot;}
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         self.node = node
</span><span class="cx">         self.directory = self.directoryModule.odInit(node)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def requestAvatarId(self, credentials):
</span><del>-        record = self.directoryModule.getUserRecord(self.directory, credentials.username)
</del><ins>+        record = self.directoryModule.getUserRecord(
+            self.directory, credentials.username
+        )
</ins><span class="cx"> 
</span><span class="cx">         if record is not None:
</span><span class="cx">             try:
</span><span class="cx">                 if &quot;algorithm&quot; not in credentials.fields:
</span><span class="cx">                     credentials.fields[&quot;algorithm&quot;] = &quot;md5&quot;
</span><span class="cx"> 
</span><del>-                challenge = 'Digest realm=&quot;%(realm)s&quot;, nonce=&quot;%(nonce)s&quot;, algorithm=%(algorithm)s' % credentials.fields
</del><ins>+                challenge = (
+                    'Digest realm=&quot;{realm}&quot;, nonce=&quot;{nonce}&quot;, '
+                    'algorithm={algorithm}'
+                    .format(**credentials.fields)
+                )
</ins><span class="cx"> 
</span><span class="cx">                 response = (
</span><del>-                    'Digest username=&quot;%(username)s&quot;, '
-                    'realm=&quot;%(realm)s&quot;, '
-                    'nonce=&quot;%(nonce)s&quot;, '
-                    'uri=&quot;%(uri)s&quot;, '
-                    'response=&quot;%(response)s&quot;,'
-                    'algorithm=%(algorithm)s'
-                ) % credentials.fields
</del><ins>+                    'Digest username=&quot;{username}&quot;, '
+                    'realm=&quot;{realm}&quot;, '
+                    'nonce=&quot;{nonce}&quot;, '
+                    'uri=&quot;{uri}&quot;, '
+                    'response=&quot;{response}&quot;,'
+                    'algorithm={algorithm}'
+                ).format(**credentials.fields)
</ins><span class="cx"> 
</span><span class="cx">             except KeyError as e:
</span><span class="cx">                 log.error(
</span><del>-                    &quot;OpenDirectory (node=%s) error while performing digest authentication for user %s: &quot;
-                    &quot;missing digest response field: %s in: %s&quot;
-                    % (self.node, credentials.username, e, credentials.fields)
</del><ins>+                    &quot;OpenDirectory (node={directory.node}) error while &quot;
+                    &quot;performing digest authentication for user &quot;
+                    &quot;{credentials.username}: missing digest response field: &quot;
+                    &quot;{field} in: {credentials.fields}&quot;
+                    .format(
+                        directory=self, credentials=credentials, field=e
+                    )
</ins><span class="cx">                 )
</span><span class="cx">                 return fail(UnauthorizedLogin())
</span><span class="cx"> 
</span><span class="cx">             try:
</span><del>-                if self.directoryModule.authenticateUserDigest(self.directory,
</del><ins>+                if self.directoryModule.authenticateUserDigest(
+                    self.directory,
</ins><span class="cx">                     self.node,
</span><span class="cx">                     credentials.username,
</span><span class="cx">                     challenge,
</span><span class="lines">@@ -107,12 +119,17 @@
</span><span class="cx">                 ):
</span><span class="cx">                     return succeed(credentials.username)
</span><span class="cx">                 else:
</span><del>-                    log.error(&quot;Failed digest auth with response: %s&quot; % (response,))
</del><ins>+                    log.error(
+                        &quot;Failed digest auth with response: {response}&quot;,
+                        response=response
+                    )
</ins><span class="cx">                     return fail(UnauthorizedLogin())
</span><span class="cx">             except Exception as e:
</span><span class="cx">                 log.error(
</span><del>-                    &quot;OpenDirectory error while performing digest authentication for user %s: %s&quot;
-                    % (credentials.username, e)
</del><ins>+                    &quot;OpenDirectory error while performing digest &quot;
+                    &quot;authentication for user {credentials.username}: &quot;
+                    &quot;{error}&quot;,
+                    credentials=credentials, error=e
</ins><span class="cx">                 )
</span><span class="cx">                 return fail(UnauthorizedLogin())
</span><span class="cx"> 
</span><span class="lines">@@ -161,7 +178,8 @@
</span><span class="cx"> 
</span><span class="cx"> class AgentGatewayResource(Resource):
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    The gateway resource which forwards incoming requests through gateway.Runner.
</del><ins>+    The gateway resource which forwards incoming requests through
+    gateway.Runner.
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     isLeaf = True
</span><span class="cx"> 
</span><span class="lines">@@ -202,10 +220,10 @@
</span><span class="cx">             tbString = tbStringIO.getvalue()
</span><span class="cx">             tbStringIO.close()
</span><span class="cx">             error = {
</span><del>-                &quot;Error&quot; : message,
-                &quot;Traceback&quot; : tbString,
</del><ins>+                &quot;Error&quot;: message,
+                &quot;Traceback&quot;: tbString,
</ins><span class="cx">             }
</span><del>-            log.error(&quot;command failed %s&quot; % (failure,))
</del><ins>+            log.error(&quot;command failed {error}&quot;, error=failure)
</ins><span class="cx">             request.write(writePlistToString(error))
</span><span class="cx">             request.finish()
</span><span class="cx"> 
</span><span class="lines">@@ -213,8 +231,10 @@
</span><span class="cx">         body = request.content.read()
</span><span class="cx">         command = readPlistFromString(body)
</span><span class="cx">         output = cStringIO.StringIO()
</span><del>-        runner = Runner(self.davRootResource, self.directory, self.store,
-            [command], output=output)
</del><ins>+        runner = Runner(
+            self.davRootResource, self.directory, self.store,
+            [command], output=output
+        )
</ins><span class="cx">         d = runner.run()
</span><span class="cx">         d.addCallback(onSuccess, output)
</span><span class="cx">         d.addErrback(onError)
</span><span class="lines">@@ -246,15 +266,22 @@
</span><span class="cx">         log.warn(&quot;Agent inactive; shutting down&quot;)
</span><span class="cx">         reactor.stop()
</span><span class="cx"> 
</span><del>-    inactivityDetector = InactivityDetector(reactor,
-        config.AgentInactivityTimeoutSeconds, becameInactive)
</del><ins>+    inactivityDetector = InactivityDetector(
+        reactor, config.AgentInactivityTimeoutSeconds, becameInactive
+    )
</ins><span class="cx">     root = Resource()
</span><del>-    root.putChild(&quot;gateway&quot;, AgentGatewayResource(store,
-        davRootResource, directory, inactivityDetector))
</del><ins>+    root.putChild(
+        &quot;gateway&quot;,
+        AgentGatewayResource(
+            store, davRootResource, directory, inactivityDetector
+        )
+    )
</ins><span class="cx"> 
</span><span class="cx">     realmName = &quot;/Local/Default&quot;
</span><del>-    portal = Portal(AgentRealm(root, [&quot;com.apple.calendarserver&quot;]),
-        [DirectoryServiceChecker(realmName)])
</del><ins>+    portal = Portal(
+        AgentRealm(root, [&quot;com.apple.calendarserver&quot;]),
+        [DirectoryServiceChecker(realmName)]
+    )
</ins><span class="cx">     credentialFactory = CustomDigestCredentialFactory(&quot;md5&quot;, realmName)
</span><span class="cx">     wrapper = HTTPAuthSessionWrapper(portal, [credentialFactory])
</span><span class="cx"> 
</span><span class="lines">@@ -283,8 +310,10 @@
</span><span class="cx">         self._becameInactive = becameInactive
</span><span class="cx"> 
</span><span class="cx">         if self._timeoutSeconds &gt; 0:
</span><del>-            self._delayedCall = self._reactor.callLater(self._timeoutSeconds,
-                self._inactivityThresholdReached)
</del><ins>+            self._delayedCall = self._reactor.callLater(
+                self._timeoutSeconds,
+                self._inactivityThresholdReached
+            )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def _inactivityThresholdReached(self):
</span><span class="lines">@@ -304,8 +333,10 @@
</span><span class="cx">             if self._delayedCall.active():
</span><span class="cx">                 self._delayedCall.reset(self._timeoutSeconds)
</span><span class="cx">             else:
</span><del>-                self._delayedCall = self._reactor.callLater(self._timeoutSeconds,
-                    self._inactivityThresholdReached)
</del><ins>+                self._delayedCall = self._reactor.callLater(
+                    self._timeoutSeconds,
+                    self._inactivityThresholdReached
+                )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def stop(self):
</span><span class="lines">@@ -361,17 +392,17 @@
</span><span class="cx">         command = readPlistFromString(command)
</span><span class="cx">         output = cStringIO.StringIO()
</span><span class="cx">         from calendarserver.tools.gateway import Runner
</span><del>-        runner = Runner(self.davRootResource, self.directory, self.store,
-            [command], output=output)
</del><ins>+        runner = Runner(
+            self.davRootResource, self.directory, self.store,
+            [command], output=output
+        )
</ins><span class="cx"> 
</span><span class="cx">         try:
</span><span class="cx">             yield runner.run()
</span><span class="cx">             result = output.getvalue()
</span><span class="cx">             output.close()
</span><span class="cx">         except Exception as e:
</span><del>-            error = {
-                &quot;Error&quot; : str(e),
-            }
</del><ins>+            error = {&quot;Error&quot;: str(e)}
</ins><span class="cx">             result = writePlistToString(error)
</span><span class="cx"> 
</span><span class="cx">         output.close()
</span><span class="lines">@@ -396,8 +427,9 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def buildProtocol(self, addr):
</span><del>-        return GatewayAMPProtocol(self.store, self.davRootResource,
-            self.directory)
</del><ins>+        return GatewayAMPProtocol(
+            self.store, self.davRootResource, self.directory
+        )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -406,7 +438,8 @@
</span><span class="cx"> #
</span><span class="cx"> 
</span><span class="cx"> command = &quot;&quot;&quot;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
</span><del>-&lt;!DOCTYPE plist PUBLIC &quot;-//Apple Computer//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;
</del><ins>+&lt;!DOCTYPE plist PUBLIC &quot;-//Apple Computer//DTD PLIST 1.0//EN&quot;
+ &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;
</ins><span class="cx"> &lt;plist version=&quot;1.0&quot;&gt;
</span><span class="cx"> &lt;dict&gt;
</span><span class="cx">         &lt;key&gt;command&lt;/key&gt;
</span><span class="lines">@@ -414,6 +447,7 @@
</span><span class="cx"> &lt;/dict&gt;
</span><span class="cx"> &lt;/plist&gt;&quot;&quot;&quot;
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> def getList():
</span><span class="cx">     # For the sample client, below:
</span><span class="cx">     from twisted.internet import reactor
</span></span></pre>
</div>
</div>

</body>
</html>