Thanks for your responses. I did consider using the req object to store my request-life variables, but then I'm still stuck with having to pass
the req object to every class in my application (and have to import modpython into every script as well) if I want to get some information about the user. I've abstracted the communications to the client at a high level in my application and I don't really want to force knowledge of modpython any further down than I need to.
Your responses will give me the required lifetime for my variables, but not the required access at all levels of code (unless req is a global variable?).
Do you have any other suggestions as to how this might be implemented?
Many thanks, Andrew
Hi all,
I'm writing an application which runs within Apache and uses mod_python to provide basic authentication and return content to the user, something like:
import modpython .... def handler(): # main part of the application starts here ...
def authenhandler(): ... # Store information about the user in an object u = new User(req.user, pass)
I'd like to be able to pass the u object somehow from authenhandler to handler in an elegant fashion, but without using global variables (as I understand it these persist for the life of the child process which will be more than one request, which is not what I want, and could be a security hole).
I suppose that I could use session variables, but since this part of my application provides a WebDAV server, basic authentication credentials are passed on each request (so I don't really want to have to look after keeping track of sessions when I don't have to). I would rather not modify all my existing classes to support an extra parameter in their constructors.
What I'm really looking for is some sort of global dictionary like PHP's $REQUEST or $SESSION, which I can assign freely to during the life of the request *from anywhere in my application* and which gets cleaned up for me automatically afterwards. Does something like this exist in mod_python?
If the approach above isn't possible, what would your recommendations be for a solution to this issue?
Many thanks for your time, Andrew James
------------------------------------------------------------------------
Subject: Re: ModPython: passing variables between handlers? From: "Diez B. Roggisch" <[EMAIL PROTECTED]> Date: Thu, 03 Feb 2005 14:38:54 +0100 To: python-list@python.org
To: python-list@python.org
Content-Transfer-Encoding: 7Bit Precedence: list MIME-Version: 1.0 References: <[EMAIL PROTECTED]> Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=us-ascii Message: 8
import modpython .... def handler(): # main part of the application starts here ...
def authenhandler(): ... # Store information about the user in an object u = new User(req.user, pass)
<snip>
What I'm really looking for is some sort of global dictionary like PHP's $REQUEST or $SESSION, which I can assign freely to during the life of the request *from anywhere in my application* and which gets cleaned up for me automatically afterwards. Does something like this exist in mod_python?
If the approach above isn't possible, what would your recommendations be for a solution to this issue?
I have absolutely no experience with mod_python, so take this with a grain of salt - but you code above suggests that there is a request object: req. You already use it: req. How about storing u in req like this:
def authenhandler(): # Store information about the user in an object req.u = new User(req.user, pass)
------------------------------------------------------------------------
Subject: Re: ModPython: passing variables between handlers? From: Steve Holden <[EMAIL PROTECTED]> Date: Thu, 03 Feb 2005 08:31:24 -0500 To: python-list@python.org
To: python-list@python.org
Content-Transfer-Encoding: 7bit Precedence: list MIME-Version: 1.0 References: <[EMAIL PROTECTED]> In-Reply-To: <[EMAIL PROTECTED]> Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=us-ascii; format=flowed Message: 9
Andrew James wrote:
Hi all,
I'm writing an application which runs within Apache and uses mod_python to provide basic authentication and return content to the user, something like:
import modpython ..... def handler(): # main part of the application starts here ...
def authenhandler(): ... # Store information about the user in an object u = new User(req.user, pass)
I'd like to be able to pass the u object somehow from authenhandler to handler in an elegant fashion, but without using global variables (as I understand it these persist for the life of the child process which will be more than one request, which is not what I want, and could be a security hole).
I suppose that I could use session variables, but since this part of my application provides a WebDAV server, basic authentication credentials are passed on each request (so I don't really want to have to look after keeping track of sessions when I don't have to). I would rather not modify all my existing classes to support an extra parameter in their constructors.
What I'm really looking for is some sort of global dictionary like PHP's $REQUEST or $SESSION, which I can assign freely to during the life of the request *from anywhere in my application* and which gets cleaned up for me automatically afterwards. Does something like this exist in mod_python?
If the approach above isn't possible, what would your recommendations be for a solution to this issue?
RTFM ;-)
If you want these values to have the same lifetime as your requests then it would appear to make sense to have them be request attributes, no?
Section 4.5.3 of the mod_python docs says little else about the request object but """You can dynamically assign attributes to it as a way to communicate between handlers.""".
regards Steve
-- http://mail.python.org/mailman/listinfo/python-list