Re: getChild in python3

"Tom Most" <[email protected]> Tue, 05 Nov 2019 14:37:52 -0800
Newsgroups gmane.comp.python.twisted.web
Message-ID <[email protected]>
--===============9053922553204227844==
Content-Type: multipart/alternative;
 boundary=7b24e002bd6c4b9a9972bacd247171ed

--7b24e002bd6c4b9a9972bacd247171ed
Content-Type: text/plain

Hi Nathaniel,

The string 'bug' needs to be a bytestring, b'bug'. This is indeed a bug, but Twisted 19.7.0 will at least generate a deprecation warning about it. A future version of Twisted will throw an exception (once the deprecation period has passed).

https://twistedmatrix.com/trac/ticket/9135

---Tom

On Tue, Nov 5, 2019, at 12:20 PM, Nathaniel Haggard wrote:
> # This code doesn't call getChild in python3, but it does in python2 (python2 throws AttributeError, but python3 doesn't) with "curl http://127.0.0.1:8803/bug/a" and Twisted==19.7.0 with python3.5.2:
> 
> from twisted.application import internet, service, strports
> from twisted.web.resource import Resource
> from twisted.web.server import Site
> from twisted.internet import reactor
> from twisted.python import log
> 
> 
> from twisted.web.resource import Resource
> 
> 
> 
> class R(Resource):
>  allowedMethods=('GET',)
>  def getChild(self, name, request):
>  pass
> 
> 
> r = Resource()
> r.putChild('bug', R())
> 
> application = service.Application('web')
> site = Site(r)
> sc = service.IServiceCollection(application)
> i = strports.service("tcp:8803", site)
> i.setServiceParent(sc)
> 
> _______________________________________________
> Twisted-web mailing list
> [email protected]
> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
> 

--7b24e002bd6c4b9a9972bacd247171ed
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html><html><head><title></title><style type=3D"text/css">p.Mso=
Normal,p.MsoNoSpacing{margin:0}</style></head><body><div>Hi Nathaniel,<b=
r></div><div><br></div><div>The string 'bug' needs to be a bytestring, b=
'bug'. This is indeed a bug, but Twisted 19.7.0 will at least generate a=
 deprecation warning about it. A future version of Twisted will throw an=
 exception (once the deprecation period has passed).<br></div><div><br><=
/div><div><a href=3D"https://twistedmatrix.com/trac/ticket/9135">https:/=
/twistedmatrix.com/trac/ticket/9135</a><br></div><div><br></div><div>---=
Tom<br></div><div><br></div><div>On Tue, Nov 5, 2019, at 12:20 PM, Natha=
niel Haggard wrote:<br></div><blockquote type=3D"cite" id=3D"qt"><div di=
r=3D"ltr"><div># This code doesn't call getChild in python3, but it does=
 in python2 (python2 throws AttributeError, but python3 doesn't) with "c=
url <a href=3D"http://127.0.0.1:8803/bug/a">http://127.0.0.1:8803/bug/a<=
/a>" and Twisted=3D=3D19.7.0 with python3.5.2:<br></div><div><br></div><=
div>from twisted.application import internet, service, strports<br></div=
><div>from twisted.web.resource import Resource<br></div><div>from twist=
ed.web.server import Site<br></div><div>from twisted.internet import rea=
ctor<br></div><div>from twisted.python import log<br></div><div><br></di=
v><div><br></div><div>from twisted.web.resource import Resource<br></div=
><div><br></div><div><br></div><div><br></div><div>class R(Resource):<br=
></div><div>&nbsp; &nbsp; allowedMethods=3D('GET',)<br></div><div>&nbsp;=
 &nbsp; def getChild(self, name, request):<br></div><div>&nbsp; &nbsp; &=
nbsp; &nbsp; pass<br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; <br></div><d=
iv><br></div><div>r =3D Resource()<br></div><div>r.putChild('bug', R())<=
br></div><div><br></div><div>application =3D service.Application('web')<=
br></div><div>site =3D Site(r)<br></div><div>sc =3D service.IServiceColl=
ection(application)<br></div><div>i =3D strports.service("tcp:8803", sit=
e)<br></div><div>i.setServiceParent(sc)<br></div><div><br></div></div><d=
iv>_______________________________________________<br></div><div>Twisted=
-web mailing list<br></div><div>[email protected]<br></div><=
div>https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web<br></=
div><div><br></div></blockquote><div><br></div></body></html>
--7b24e002bd6c4b9a9972bacd247171ed--

--===============9053922553204227844==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KVHdpc3RlZC13
ZWIgbWFpbGluZyBsaXN0ClR3aXN0ZWQtd2ViQHR3aXN0ZWRtYXRyaXguY29tCmh0dHBzOi8vdHdp
c3RlZG1hdHJpeC5jb20vY2dpLWJpbi9tYWlsbWFuL2xpc3RpbmZvL3R3aXN0ZWQtd2ViCg==

--===============9053922553204227844==--