[Twisted-web] Twisted-web Digest, Vol 151, Issue 2

Jean-Paul Calderone exarkun at twistedmatrix.com
Thu Aug 9 11:55:48 MDT 2018


On Thu, Aug 9, 2018 at 1:32 PM Jason Harrison <drjasonharrison at gmail.com>
wrote:

> On Thu, 9 Aug 2018 at 09:31 am Jean-Paul Calderone <
> exarkun at twistedmatrix.com> wrote:
>
>> In the code you posted, DelayedResponse is the root resource.  The root
>> resource *always* has to provide a child resource.  If someone requests
>> /foo then the child is "foo".  If someone requests "/" then the child is
>> "".
>>
>> isLeaf = True is a shortcut that stops traversal and uses the current
>> resource as the requested resource.  Without this, DelayedResponse must
>> have a child or it can only produce a 404.
>>
>> Maybe that explains it?  If there are examples in the documentation that
>> have root resources with no children and without isLeaf = True then
>> perhaps
>> they are also broken and should be fixed.  If you see any, please point
>> them out.
>>
>>
> Thank you for the explanation! Let's see if I understand your explanation
> and the variation in the examples.
>
>
> https://twistedmatrix.com/documents/current/web/howto/web-in-60/custom-codes.html
> does not have isLeaf = True because it has:
>
> root = Resource()
> root.putChild(b"buy", PaymentRequired())
> factory = Site(root)
>
>
>
> https://twistedmatrix.com/documents/current/web/howto/web-in-60/dynamic-content.html
> does have isLeaf = True because it does not have a .putChild()
>
> The explanation about isLeaf could be improved by:
>
> Setting isLeaf to True indicates that ClockPage resources will never have
> any children.
>
> Without this, the ClockPage resources must have a child or it can only
> produce a 404.
>
>
>
> https://twistedmatrix.com/documents/current/web/howto/web-in-60/dynamic-dispatch.html
> does not have isLeaf = True because it defines getChild for the root class
> Calendar
>
> So does not have isLeaf = True because it was written as an .rpy script??
>
> http://twistedmatrix.com/documents/current/web/howto/web-in-60/asynchronous.html
>
>
You got all these explanations right.  To expand on the rpy case, the root
resource is a static.File("/directory/containing/script/") and the rpy's
resource is accessed as a child of that (which child depends on what the
rpy script is named).

I agree the explanation about isLeaf in that document could be improved.
Perhaps there should be a new web in 60 seconds dedicated to isLeaf instead
of just having a drive-by explanation in another example.


> Thank you again,
> -Jason
>
>
>
> _______________________________________________
> Twisted-web mailing list
> Twisted-web at twistedmatrix.com
> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-web/attachments/20180809/bd074480/attachment.html>


More information about the Twisted-web mailing list