[Twisted-web] livepage breaks after reload

Matt Goodall matt at pollenation.net
Wed Jan 26 16:03:09 MST 2005


On Wed, 2005-01-26 at 19:29 +0100, noema wrote:
> > You're locate child should look something more like ...
> > 
> > def locateChild(self, context, segments):
> > 
> >     # Do whatever you need to do here, probably returning
> >     # a resource and the remaining segments.
> > 
> >     # I don't know what it is so let Page (my subclass) try.
> >     return rend.Page.locateChild(self, context, segments)
> 
> 
> I am not sure I fully understand what you mean. Am I not exactly doing 
> what you are suggesting?!  I return a resource and the remaining 
> segments. Just that in my case the resource is the current resource 
> itself and the remaining segments are empty. (to make any child valid 
> and be handled by MyPage (which it does just not with livepage support))

Oops, my reasoning was completely flawed although I'm still confident
I'm correct about the problem.

Liveevil connects to the nevow_liveOutput and nevow_liveInput child
resources (see rend.LiveEvilChildMixin). By overriding locateChild, and
not allowing the super class to play, you are blocking access to those
liveevil resources.

> 
>  > return rend.Page.locateChild(self, context, segments)
> 
> Isn't this returned/called anyways if I wouldn't overwrite the inherited 
> locateChild methode.

Yes, *if* you don't override locateChild. But in your code, the problem
occurs once you uncomment locateChild and replace rend.Page's
implementation of locateChild.

If you want to handle all segments but still let Liveevil work, perhaps
the following will help:

        def locateChild(self, ctx, segments):
            r = rend.Page(self, ctx, segments)
            if r is not appserver.NotFound:
                return r
            return self, ()
        
That /should/ let the super class locate the resources needed by
liveevil and make your page handle all other segments.

Hope this makes more sense this time ;-).

Cheers, Matt

> 
> 
> 
> >>What follows is some code that illustrates exactly that. Javascript 
> >>events come perfectly through until I uncommend the localChild methode.
> >>
> >>#noema
> >>
> >>
> >>
> >>#################### START OF .TAC FILE ########################
> >>
> >>import random
> >>from twisted.application import service, internet
> >>from nevow import loaders, rend, tags, livepage, url
> >>
> >>
> >>class MyPage(rend.Page):
> >>     addSlash = True
> >>
> >>     #def locateChild(self, context, segments):
> >>     #    #store the rest of the url for any kind of manual processing
> >>     #    self.postpath = segments
> >>     #    return self, ()
> >>
> >>     def onLinkAction(self, client):
> >>         client.set('atag',
> >>             random.choice(('one', 'two', 'three', 'four', 'five')))
> >>
> >>     def render_link(self, context, data):
> >>         return tags.a(onclick=livepage.handler(self.onLinkAction),
> >>                     href=url.here, id="atag")['click!']
> >>
> >>
> >>     def render_glue(self, context, data):
> >>         return livepage.glue
> >>
> >>
> >>     docFactory = loaders.stan(
> >>     tags.html[
> >>         tags.head[
> >>             tags.title["mypage"],
> >>           ],
> >>         tags.body[
> >>             tags.div[
> >>                 render_link
> >>             ],
> >>             tags.span(render=render_glue)
> >>         ]
> >>     ])
> >>
> >>
> >>
> >>application = service.Application('mypage')
> >>internet.TCPServer(8080, livepage.LiveSite(MyPage()))\
> >>     .setServiceParent(application)
> >>
> >>
> >>#################### END OF .TAC FILE ##########################
> 
> 
> _______________________________________________
> Twisted-web mailing list
> Twisted-web at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web




More information about the Twisted-web mailing list