[Twisted-Python] What is the right way to pass variables from Site to Resource?
I've got some global state and configuration information. It seems to me that they ought to be members of my Site, but I don't see any obvious way in a Resource.render_* to get the current Site. Neither Request nor Resource have a instance or method that returns its Site that I can find. Am I missing something, or am I confused about the Twisted way of doing things?
On 04:47 pm, markscottwright@gmail.com wrote:
I've got some global state and configuration information. It seems to me that they ought to be members of my Site, but I don't see any obvious way in a Resource.render_* to get the current Site. Neither Request nor Resource have a instance or method that returns its Site that I can find. Am I missing something, or am I confused about the Twisted way of doing things?
The Request object does have a "site" attribute. It's not documented on the interface, so perhaps you should be careful in your use of it. Or, you could file a ticket explaining why it would be a good idea to have the attribute added to the interface. Jean-Paul
On Mon, Mar 01, 2010 at 04:47:49PM +0000, markscottwright@gmail.com wrote:
I've got some global state and configuration information. It seems to me that they ought to be members of my Site, but I don't see any obvious way in a Resource.render_* to get the current Site. Neither Request nor Resource have a instance or method that returns its Site that I can find. Am I missing something, or am I confused about the Twisted way of doing things?
as general rule i prefer pass variables through constructors but i don't know how do you instance your Resource(s).
On Mon, Mar 1, 2010 at 11:47 AM,
I've got some global state and configuration information. It seems to me that they ought to be members of my Site, but I don't see any obvious way in a Resource.render_* to get the current Site. Neither Request nor Resource have a instance or method that returns its Site that I can find. Am I missing something, or am I confused about the Twisted way of doing things?
I think you are missing something - request has attribute `site' set on it which will give you the Site object. -Drew
participants (4)
-
Drew Smathers
-
exarkun@twistedmatrix.com
-
Marco Giusti
-
markscottwright@gmail.com