<!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>[12681] CalendarServer/trunk/txweb2/resource.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/12681">12681</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2014-02-12 13:18:21 -0800 (Wed, 12 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Call getChild() in locateResource()</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxweb2resourcepy">CalendarServer/trunk/txweb2/resource.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktxweb2resourcepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txweb2/resource.py (12680 => 12681)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txweb2/resource.py        2014-02-12 20:16:50 UTC (rev 12680)
+++ CalendarServer/trunk/txweb2/resource.py        2014-02-12 21:18:21 UTC (rev 12681)
</span><span class="lines">@@ -10,8 +10,8 @@
</span><span class="cx"> # copies of the Software, and to permit persons to whom the Software is
</span><span class="cx"> # furnished to do so, subject to the following conditions:
</span><span class="cx"> #
</span><del>-# The above copyright notice and this permission notice shall be included in all
-# copies or substantial portions of the Software.
</del><ins>+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
</ins><span class="cx"> #
</span><span class="cx"> # THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
</span><span class="cx"> # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
</span><span class="lines">@@ -35,6 +35,9 @@
</span><span class="cx"> from txweb2 import iweb, http, server, responsecode
</span><span class="cx"> 
</span><span class="cx"> from twisted.internet.defer import maybeDeferred
</span><ins>+
+
+
</ins><span class="cx"> class RenderMixin(object):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Mix-in class for L{iweb.IResource} which provides a dispatch mechanism for
</span><span class="lines">@@ -42,11 +45,14 @@
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     def allowedMethods(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        @return: A tuple of HTTP methods that are allowed to be invoked on this resource.
</del><ins>+        @return: A tuple of HTTP methods that are allowed to be invoked on this
+            resource.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if not hasattr(self, &quot;_allowed_methods&quot;):
</span><del>-            self._allowed_methods = tuple([name[5:] for name in dir(self) 
-                if name.startswith('http_') and getattr(self, name) is not None])
</del><ins>+            self._allowed_methods = tuple(
+                name[5:] for name in dir(self)
+                if name.startswith('http_') and getattr(self, name) is not None
+            )
</ins><span class="cx">         return self._allowed_methods
</span><span class="cx"> 
</span><span class="cx">     def checkPreconditions(self, request):
</span><span class="lines">@@ -62,7 +68,8 @@
</span><span class="cx">         # GET or HEAD request.
</span><span class="cx">         #
</span><span class="cx">         # For other methods, we need to know to bail out before request
</span><del>-        # processing, especially for methods that modify server state (eg. PUT).
</del><ins>+        # processing, especially for methods that modify server state (eg.
+        # PUT).
</ins><span class="cx">         # We also would like to do so even for methods that don't, if those
</span><span class="cx">         # methods might be expensive to process.  We're assuming that GET and
</span><span class="cx">         # HEAD are not expensive.
</span><span class="lines">@@ -81,15 +88,16 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         See L{iweb.IResource.renderHTTP}.
</span><span class="cx"> 
</span><del>-        This implementation will dispatch the given C{request} to another method
-        of C{self} named C{http_}METHOD, where METHOD is the HTTP method used by
-        C{request} (eg. C{http_GET}, C{http_POST}, etc.).
</del><ins>+        This implementation will dispatch the given C{request} to another
+        method of C{self} named C{http_}METHOD, where METHOD is the HTTP method
+        used by C{request} (eg. C{http_GET}, C{http_POST}, etc.).
</ins><span class="cx"> 
</span><span class="cx">         Generally, a subclass should implement those methods instead of
</span><span class="cx">         overriding this one.
</span><span class="cx"> 
</span><del>-        C{http_*} methods are expected provide the same interface and return the
-        same results as L{iweb.IResource}C{.renderHTTP} (and therefore this method).
</del><ins>+        C{http_*} methods are expected provide the same interface and return
+        the same results as L{iweb.IResource}C{.renderHTTP} (and therefore this
+        method).
</ins><span class="cx"> 
</span><span class="cx">         C{etag} and C{last-modified} are added to the response returned by the
</span><span class="cx">         C{http_*} header, if known.
</span><span class="lines">@@ -172,6 +180,8 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         raise NotImplementedError(&quot;Subclass must implement render method.&quot;)
</span><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class Resource(RenderMixin):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     An L{iweb.IResource} implementation with some convenient mechanisms for
</span><span class="lines">@@ -190,7 +200,7 @@
</span><span class="cx">         of this resource which matches one or more of the given C{segments} in
</span><span class="cx">         sequence, and a list of remaining segments.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        w = getattr(self, 'child_%s' % (segments[0],), None)
</del><ins>+        w = self.getChild(segments[0])
</ins><span class="cx"> 
</span><span class="cx">         if w:
</span><span class="cx">             r = iweb.IResource(w, None)
</span><span class="lines">@@ -246,11 +256,14 @@
</span><span class="cx">     def http_GET(self, request):
</span><span class="cx">         if self.addSlash and request.prepath[-1] != '':
</span><span class="cx">             # If this is a directory-ish resource...
</span><del>-            return http.RedirectResponse(request.unparseURL(path=request.path + '/'))
</del><ins>+            return http.RedirectResponse(
+                request.unparseURL(path=request.path + '/')
+            )
</ins><span class="cx"> 
</span><span class="cx">         return super(Resource, self).http_GET(request)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> class PostableResource(Resource):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     A L{Resource} capable of handling the POST request method.
</span><span class="lines">@@ -274,11 +287,12 @@
</span><span class="cx">         @param request: the request to process.
</span><span class="cx">         @return: an object adaptable to L{iweb.IResponse}.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        return server.parsePOSTData(request,
-            self.maxMem, self.maxFields, self.maxSize
-            ).addCallback(lambda res: self.render(request))
</del><ins>+        return server.parsePOSTData(
+            request, self.maxMem, self.maxFields, self.maxSize
+        ).addCallback(lambda res: self.render(request))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> class LeafResource(RenderMixin):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     A L{Resource} with no children.
</span><span class="lines">@@ -288,6 +302,8 @@
</span><span class="cx">     def locateChild(self, request, segments):
</span><span class="cx">         return self, server.StopTraversal
</span><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class RedirectResource(LeafResource):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     A L{LeafResource} which always performs a redirect.
</span><span class="lines">@@ -305,8 +321,12 @@
</span><span class="cx">         self._kwargs = kwargs
</span><span class="cx"> 
</span><span class="cx">     def renderHTTP(self, request):
</span><del>-        return http.RedirectResponse(request.unparseURL(*self._args, **self._kwargs))
</del><ins>+        return http.RedirectResponse(
+            request.unparseURL(*self._args, **self._kwargs)
+        )
</ins><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class WrapperResource(object):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     An L{iweb.IResource} implementation which wraps a L{RenderMixin} instance
</span><span class="lines">@@ -344,4 +364,7 @@
</span><span class="cx">         return self.resource.getChild(name)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-__all__ = ['RenderMixin', 'Resource', 'PostableResource', 'LeafResource', 'WrapperResource']
</del><ins>+__all__ = [
+    'RenderMixin', 'Resource',
+    'PostableResource', 'LeafResource', 'WrapperResource'
+]
</ins></span></pre>
</div>
</div>

</body>
</html>