Re: Twisted-web Digest, Vol 151, Issue 2
Jean-Paul Calderone <[email protected]> Thu, 9 Aug 2018 13:55:48 -0400
| Newsgroups | gmane.comp.python.twisted.web |
|---|---|
| Message-ID | <CAEeXt4Ph30Wmq1Yaa95X3hexpWBnq8+hzyAtW8TqP3zXF-BsTQ@mail.gmail.com> |
--===============6131387856482849732== Content-Type: multipart/alternative; boundary="000000000000f8886f05730456b0" --000000000000f8886f05730456b0 Content-Type: text/plain; charset="UTF-8" On Thu, Aug 9, 2018 at 1:32 PM Jason Harrison <[email protected]> wrote: > On Thu, 9 Aug 2018 at 09:31 am Jean-Paul Calderone < > [email protected]> 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 > [email protected] > https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web > --000000000000f8886f05730456b0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_quote"><div dir=3D"ltr">On Thu, Aug 9,= 2018 at 1:32 PM Jason Harrison <<a href=3D"mailto:drjasonharrison@gmail= .com">[email protected]</a>> wrote:<br></div><blockquote class= =3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd= ing-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_extra"><div><div class= =3D"m_8409394774415405209gmail_signature">On Thu, 9 Aug 2018 at 09:31 am Je= an-Paul Calderone <<a href=3D"mailto:[email protected]" target= =3D"_blank">[email protected]</a>> wrote:</div></div><div class= =3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px = 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> In the code you posted, DelayedResponse is the root resource.=C2=A0 The roo= t<br> resource *always* has to provide a child resource.=C2=A0 If someone request= s<br> /foo then the child is "foo".=C2=A0 If someone requests "/&q= uot; then the child is "".<br> <br> isLeaf =3D True is a shortcut that stops traversal and uses the current<br> resource as the requested resource.=C2=A0 Without this, DelayedResponse mus= t<br> have a child or it can only produce a 404.<br> <br> Maybe that explains it?=C2=A0 If there are examples in the documentation th= at<br> have root resources with no children and without isLeaf =3D True then perha= ps<br> they are also broken and should be fixed.=C2=A0 If you see any, please poin= t<br> them out.<br><br></blockquote><div><br></div><div>Thank you for the explana= tion! Let's see if I understand your explanation and the variation in t= he examples.</div><div><br></div><div><a href=3D"https://twistedmatrix.com/= documents/current/web/howto/web-in-60/custom-codes.html" target=3D"_blank">= https://twistedmatrix.com/documents/current/web/howto/web-in-60/custom-code= s.html</a><br></div><div>does not have isLeaf =3D True because it has:</div= ></div></div><blockquote style=3D"margin:0px 0px 0px 40px;border:none;paddi= ng:0px"><div class=3D"gmail_extra"><div class=3D"gmail_quote"><div><div>roo= t =3D Resource()</div></div></div></div><div class=3D"gmail_extra"><div cla= ss=3D"gmail_quote"><div><div>root.putChild(b"buy", PaymentRequire= d())</div></div></div></div><div class=3D"gmail_extra"><div class=3D"gmail_= quote"><div><div>factory =3D Site(root)</div></div></div></div></blockquote= ><div><br></div><div><a href=3D"https://twistedmatrix.com/documents/current= /web/howto/web-in-60/dynamic-content.html" target=3D"_blank">https://twiste= dmatrix.com/documents/current/web/howto/web-in-60/dynamic-content.html</a><= /div><div>does have isLeaf =3D True because it does not have a .putChild()= =C2=A0</div><div><br></div><div>The explanation about isLeaf could be impro= ved by:</div><div><br></div><blockquote style=3D"margin:0px 0px 0px 40px;bo= rder:none;padding:0px"><div><div>Setting isLeaf to True indicates that Cloc= kPage resources will never have any children.</div></div></blockquote><bloc= kquote style=3D"margin:0px 0px 0px 40px;border:none;padding:0px"><div>Witho= ut this, the=C2=A0<span style=3D"font-size:small;background-color:rgb(255,2= 55,255);text-decoration-style:initial;text-decoration-color:initial;float:n= one;display:inline">ClockPage</span>=C2=A0resources must have a child or it= can only produce a 404.</div></blockquote><div><div><br></div></div><div><= a href=3D"https://twistedmatrix.com/documents/current/web/howto/web-in-60/d= ynamic-dispatch.html" target=3D"_blank">https://twistedmatrix.com/documents= /current/web/howto/web-in-60/dynamic-dispatch.html</a></div><div>does not h= ave isLeaf =3D True because it defines getChild for the root class Calendar= </div><div><br></div><div>So=C2=A0<span style=3D"font-size:small;background= -color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color= :initial;float:none;display:inline"><span style=3D"text-decoration-style:in= itial;text-decoration-color:initial;float:none;display:inline">does not hav= e isLeaf =3D True because it was written as an .rpy script??</span></span><= /div><div><a href=3D"http://twistedmatrix.com/documents/current/web/howto/w= eb-in-60/asynchronous.html" target=3D"_blank">http://twistedmatrix.com/docu= ments/current/web/howto/web-in-60/asynchronous.html</a><br></div><div><div = style=3D"font-size:small;text-decoration-style:initial;text-decoration-colo= r:initial"><br></div></div></div></blockquote><div><br></div><div>You got a= ll these explanations right.=C2=A0 To expand on the rpy case, the root reso= urce is a static.File("/directory/containing/script/") and the rp= y's resource is accessed as a child of that (which child depends on wha= t the rpy script is named).</div><div><br></div><div>I agree the explanatio= n about isLeaf in that document could be improved.=C2=A0 Perhaps there shou= ld be a new web in 60 seconds dedicated to isLeaf instead of just having a = drive-by explanation in another example.</div><div>=C2=A0</div><blockquote = class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid= ;padding-left:1ex"><div dir=3D"ltr"><div><div style=3D"font-size:small;text= -decoration-style:initial;text-decoration-color:initial"></div><div style= =3D"font-size:small;text-decoration-style:initial;text-decoration-color:ini= tial">Thank you again,</div><div style=3D"font-size:small;text-decoration-s= tyle:initial;text-decoration-color:initial">-Jason</div><br class=3D"m_8409= 394774415405209gmail-Apple-interchange-newline"></div><div><br></div><div><= div class=3D"gmail_extra"><div class=3D"gmail_quote"><div><br></div></div><= /div></div></div> _______________________________________________<br> Twisted-web mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">Twisted-= [email protected]</a><br> <a href=3D"https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" = rel=3D"noreferrer" target=3D"_blank">https://twistedmatrix.com/cgi-bin/mail= man/listinfo/twisted-web</a><br> </blockquote></div></div> --000000000000f8886f05730456b0-- --===============6131387856482849732== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KVHdpc3RlZC13 ZWIgbWFpbGluZyBsaXN0ClR3aXN0ZWQtd2ViQHR3aXN0ZWRtYXRyaXguY29tCmh0dHBzOi8vdHdp c3RlZG1hdHJpeC5jb20vY2dpLWJpbi9tYWlsbWFuL2xpc3RpbmZvL3R3aXN0ZWQtd2ViCg== --===============6131387856482849732==--