[Twisted-web] Get access to Avatar from Resource object?

Glyph Lefkowitz glyph at twistedmatrix.com
Thu Feb 23 13:33:16 EST 2012


On Feb 23, 2012, at 12:37 PM, Jacek Furmankiewicz wrote:

> D'oh!
> That's what happens when you copy code from the web, sorry :-(
> 
> So just a follow up to my other question: how do I add my child resources?

However you like!  I'm not sure what you're asking here; TestRealm returns a resource object, to which you may add child resources in any manner you see fit.  Usually this is done simply by having methods on that object (getChild) which can synthesize appropriate child resources when asked for them, but I wouldn't call that a "best practice" or anything; it's just something that makes sense a lot of the time.

> Does my TestRealm need to extend Resource? Is that the recommended approach?

No.  TestRealm should *return* IResource providers (when asked for them - that's what the 'interfaces' argument is for).  It itself should just provide IRealm, and it definitely shouldn't inherit from anything else.

-glyph


More information about the Twisted-web mailing list