[Twisted-web] HTTPAuthSessionWrapper render

Jared Gisin jared.gisin at isilon.com
Wed Jul 1 10:12:25 EDT 2009


I guess the problem that I have is that there's an example for it, where
you wrap the root object that gets passed into a
twisted.web.server.Site() instantiation. My application doesn't require
auth for every thing in the site; only certain subtrees of the Resource
hierarchy, so how in the world in a Resource's __init__(self): would I
hook this up to something that I'd pass into self.putChild()

Here, I've modified the realm to hand back the Resource object passed in
upon authentication.

site = server.Site(
guard.HTTPAuthSessionWrapper(Portal(APIRealm(Root()), CRED_CHECKERS),
	CRED_FACTORIES))


But suppose I have under Root() a resource V1, then the following
doesn't work:

class Root(Resource):

    def __init__(self):
        Resource.__init__(self)

        self.putChild('1', guard.HTTPAuthSessionWrapper(
                       Portal(APIRealm(V1()), CRED_CHECKERS),
                          CRED_FACTORIES))

	  Self.putChild('', self)


What winds up happening is that it things an instance of
HTTPAuthSessionWrapper is the child of Root, and when I access a URI
such as /1?blah, which I expect to render something, it winds up calling
the render method of that HTTPAuthSessionWrapper, which is wrong. It
needs to call render of V1(), not it's wrapper. What do I have wrong?

-Jared

-----Original Message-----
From: twisted-web-bounces at twistedmatrix.com
[mailto:twisted-web-bounces at twistedmatrix.com] On Behalf Of Jean-Paul
Calderone
Sent: Tuesday, June 30, 2009 5:17 PM
To: Twisted Web World
Subject: Re: [Twisted-web] HTTPAuthSessionWrapper render

On Tue, 30 Jun 2009 15:38:46 -0700, Jared Gisin <jared.gisin at isilon.com>
wrote:
>It seems to be completely broken for wrapping a child resource. You can
>wrap the site root resource, but not a child?  What am I missing here?

Its render method only ever raises NotImplementedError.  This is because
it isn't ever supposed to be invoked.  If the code is working correctly,
then the only thing which will ever happen to an HTTPAuthSessionWrapper
is that some child of it will be requested.  That child may be rendered.

If you're seeing HTTPAuthSessionWrapper.render get invoked, then it may
be due to a bug in Twisted or due to a bug in how your code uses the
wrapper.  Can you provide more details about what you're doing?  Perhaps
we can track down the cause of the behavior you're observing.

Jean-Paul

_______________________________________________
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