[Twisted-web] Re: Thoughts on documentation, wading into Twisted, Nevow, etc.

Valentino Volonghi aka Dialtone dialtone at divmod.com
Tue Jul 11 20:10:24 CDT 2006


On Tue, 11 Jul 2006 15:10:58 -0400 (EDT), lloyd at paisite.com wrote:
>Hi Valentino,
>
>On Tue, July 11, 2006 8:07 am, Valentino Volonghi aka Dialtone wrote:
>
>> For IResource the right example is most_basic which uses the following
>> code:
>
>Note that I've added the road map to http://twisted.paisite.com.
>
>When I started to rebuild my Twisted environment, I realized that version
>updates may have broken Turkey Adventures one through four.
>
>Todo list:
>
>1. Retest Adventures one through four using current Twisted versions.
>2. Update Adventures one through four if necessary
>
>Once I have my environment back up I'll try to tackle these two tasks. If
>anyone else feels so inclined, feel free to jump in.

>From what I've seen in your current adventures I don't think you'll need to
update anything since currently you only use twisted.web which hasn't been
updated for a long time (and twisted.web2 will take its place when ready).

To be honest this changing-situation is true for Nevow too since in a branch
(already working and waiting review and approval) Nevow introduces 2 new objects
and a new way of dealing with pages that removes the context (ctx argument).

This is why in the next adventures I wouldn't spend much time talking about the
context except for some basic notions that are needed to do what the new objects
allow without using it. Don't worry about it too much then.

>Re: IRequest code:
>
>Great start, Valentino!
>
>Questions:
>
>-- Does this need some kind or wrapper to run it or will it run as is?

It will run as is on top of Nevow (which introduces some wrappers for twisted.web).

from twisted.internet import reactor
from nevow import appserver
site = appserver.NevowSite(root)
reactor.listenTCP(8080, site)

this lines added at the end of the file will make it work. You can run the
example obtained in this way using the standard:

python myscript.py
Then browing to http://localhost:8080/ will start the experience.

An alternative solution uses the tac file approach and is the following:

from twisted.application import strports, service
from nevow import appserver
application = service.Application('example')
website = appserver.NevowSite(root)
webservice = strports.service('8080', website)
webservice.setServiceParent(application)

You can run the example obtained in this way using:
twistd -noy myscript.tac
then browsing to http://localhost:8080/ will start the experience.

The tac extension is arbitrary and only used because the file uses this alternative
way of setting up the application.

>-- What's the step-by-step procedure to get it running?

See above.

>-- What should we see when we do get it running?

A root page with an Hello world and a link to a child page named foo.
Trying to get any other url except the one with the child foo will result in a 404.

If you go in the foo child you'll see a page with the content 'you are in foo'
and a link to foo's child page baz. Any other child page will result in a 404.

If you go in the baz child you'll see a page with the content 'you are in baz'.
This page has no children and any other url will result in a 404.

>-- How does it work?
I think it is explained in the comments. I wouldn't know how to explain it better
without precise questions. :)

>-- From the big picture point-of-view, what have we learned by running
>this code?

We have learned that Nevow is fundamentally based on the following request
processing schema:

arrives request \
                 --> root resource \
                                    --> root.locateChild(url segments)
                                    . child_resource.locateChild(url segments[1:])
                                    . child_resource2.locateChild(url segments[2:])
                                    . so forth until url segments == ()
                            ==> FOUND RIGHT RESOURCE
                                    ==> RIGHT_RESOURCE.renderHTTP()  \
browser <================================


HTH.




More information about the Twisted-web mailing list