[Twisted-web] some questions about twisted.web

Phil Mayers p.mayers at imperial.ac.uk
Tue Apr 7 13:10:52 EDT 2009

Jack Moffitt wrote:
>> When you start your application:
>>     from twisted.python import log
>>     log.startLogging(sys.stdout)
> Now I've just deluged the poor user with lots of factory start and
> stops.  All I want is normal HTTP style logs.  Twisted's logging
> infrastructure has its place, but it is not quite ready to produce
> user friendly output for a simple utility.

That's probably a bug/feature request.

>> Or, even better, create an Application object and use twistd(1) to start
>> your service. Using twistd(1), you have a choice to daemonize your process
>> or not.
> Great, now the user has to edit a tac file just to configure the
> thing.  I'd rather them be able to type "tape" and not have to worry
> about twistd -ny some.tac.  I use tac files a lot, but they don't make
> much sense for simple utilities.  It sucks that it's either/or with
> Twisted applications.

I'm assuming "tape" is your application?

>> These sessions helped to reinforce for me the need to repeat this frequently
>> for our users: if Twisted is doing something which confuses you but seems
>> wrong, please go ahead and file a bug on twistedmatrix.com.
> This mailing list should be indexed by Google as well.  I do plan to
> file the bugs we find here as well.
>> * The only way to stick something in the tree at an arbitrary location
>> seems to be to walk the tree to that spot, creating dummy locations as
>> you go.
>> Override locateChild
> What is that?   I see no such function:
> Not in IResource:
> http://twistedmatrix.com/documents/current/api/twisted.web.resource.IResource.html
> Not in the server.Site:
> http://twistedmatrix.com/documents/current/api/twisted.web.server.Site.html
> grep -r doesn't show it in the twisted/web or any child directories.
> Not even in SVN trunk.

It's in nevow's appserver/resource sub-classes, not in t.web; not that 
this helps you of course.

Basically, you're right - the resource dispatch in t.web is, to say the 
least, difficult. Sadly, you need to change both the http server, 
channel and request code to alter it (which is what Nevow does)

>> I find it extremely weird coming from several other web
>> frameworks.
>> Twisted initially seems very different, no matter what framework you came
>> from.
> I grok Twisted just fine.  This may be my first post to twisted-web,
> but I've been hacking on and around Twisted for some time.  Even
> Apache doesn't work this way.  I can tell apache that my proxy is at
> /some/url/over/here and it will work.  It will return 404s for the
> intermediate URLs.  Because Resources only have immediate children and
> paths are only dealt with in single element pieces, there doesn't seem
> to be a way to do this in Twisted Web.  It feels weird that the tree
> must be complete.  It feels weird that paths are dealt with in tiny
> sections.

I believe the eventual plan is to have t.web use the nevow appserver & 
resource model, with backwards compatibility stubs.

>> * Related to the above, the handling of foo vs. foo/ is pretty
>> confusing.  foo/ is considered the '' child of foo.  This is pretty
>> yuck to me.  Unfortunately, I don't have any creative suggestions
>> about how to do it better right now.
>> addSlash = True
> This does not exist in Resource or in server.Site.  What am I missing?
>  It's not mentioned in the docs either.

Again, that's a nevow thing. This does have an equivalent in t.web - set

isLeaf = True

Basically, you want the nevow resource model. Sadly, that loses you the 
easy render_METHOD helpers, though you can easily re-add them by hooking 
renderHTTP and dispatching on a base class.

To the devs: If there are a list of tickets for bringing the nevow stuff 
into t.web, I'd probably be able to spend some time working on them.

More information about the Twisted-web mailing list