Is there a supported way for adding data to a twisted.web request object. I am not thinking about the session, because I only want the data to last the current request, the typical use is for a resource to add some data that would be used by a child resource. I know I could use the args dictionary but that seems a little awkward as that is supposed to contain the query string/post for the page.
On Thu, 2004-09-16 at 09:36, Syver Enstad wrote:
Is there a supported way for adding data to a twisted.web request object. I am not thinking about the session, because I only want the data to last the current request, the typical use is for a resource to add some data that would be used by a child resource. I know I could use the args dictionary but that seems a little awkward as that is supposed to contain the query string/post for the page.
Request is Componentized so you can attach data to the request. Here's how it works ... Define an interface and an implementation: class IFoo(Interface): pass class Foo: __implements__ = IFoo, To associate some Foo data with the request do: foo = Foo() foo.bar = 'bar' request.setComponent(IFoo, foo) And finally, do something like this to retrieve the data from the request: foo = request.getComponent(IFoo) Cheers, Matt -- __ / \__ Matt Goodall, Pollenation Internet Ltd \__/ \ w: http://www.pollenation.net __/ \__/ e: matt@pollenation.net / \__/ \ t: +44 (0)113 2252500 \__/ \__/ / \ Any views expressed are my own and do not necessarily \__/ reflect the views of my employer.
Matt Goodall <matt@pollenation.net> writes:
request.setComponent(IFoo, foo)
And finally, do something like this to retrieve the data from the request:
foo = request.getComponent(IFoo)
Thanks Matt that certainly seems to do what I want. If the foo object also disappear when the request is finished then this is exactly what I want.
On Thu, 2004-09-16 at 10:52, Syver Enstad wrote:
Matt Goodall <matt@pollenation.net> writes:
request.setComponent(IFoo, foo)
And finally, do something like this to retrieve the data from the request:
foo = request.getComponent(IFoo)
Thanks Matt that certainly seems to do what I want. If the foo object also disappear when the request is finished then this is exactly what I want.
Normal Python garbage collection rules should apply, i.e. there are no guarantees about what will happen but as long as you don't hang on to other references to foo then foo will get GC'd at the same time as the request object. Cheers, Matt -- Matt Goodall <matt@pollenation.net>
Matt Goodall <matt@pollenation.net> writes:
On Thu, 2004-09-16 at 10:52, Syver Enstad wrote:
Thanks Matt that certainly seems to do what I want. If the foo object also disappear when the request is finished then this is exactly what I want.
Normal Python garbage collection rules should apply, i.e. there are no guarantees about what will happen but as long as you don't hang on to other references to foo then foo will get GC'd at the same time as the request object.
Of course, I was just talking about the refernce that the request kept. I checked it, the request value disappears between requests. Very nice I am using it already now to maintain some link information.
participants (2)
-
Matt Goodall
-
Syver Enstad