Iain Mackay
imm at iain-mackay.org
Tue Jul 6 21:09:07 EDT 2004
-----Original Message----- From: mod_python-bounces at modpython.org [mailto:mod_python-bounces at modpython.org] On Behalf Of mod_python-request at modpython.org Sent: 06 July 2004 16:02 To: mod_python at modpython.org Subject: Mod_python Digest, Vol 16, Issue 7 Send Mod_python mailing list submissions to mod_python at modpython.org To subscribe or unsubscribe via the World Wide Web, visit http://mailman.modpython.org/mailman/listinfo/mod_python or, via email, send a message with subject or body 'help' to mod_python-request at modpython.org You can reach the person managing the list at mod_python-owner at modpython.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Mod_python digest..." Today's Topics: 1. query_vars and form_vars (mod_python user) 2. Re: Does mod_python have a global dictionary or sorts? (Byron Ellacott) 3. Re: query_vars and form_vars (Jorey Bump) 4. Re: query_vars and form_vars (Jorey Bump) 5. Re: query_vars and form_vars (Byron Ellacott) 6. Re: query_vars and form_vars (Jorey Bump) 7. Re: query_vars and form_vars (Daniel J. Popowich) 8. Re: query_vars and form_vars (Gregory (Grisha) Trubetskoy) 9. Version Compatibility (Dan Olsen) 10. erratic behaviour from mptest.py (John Riehl) ---------------------------------------------------------------------- Message: 1 Date: Mon, 05 Jul 2004 12:49:50 -0700 From: mod_python user <python at theorb.net> Subject: [mod_python] query_vars and form_vars To: mod_python at modpython.org Message-ID: <40E9B0DE.5040900 at theorb.net> Content-Type: text/plain; charset=us-ascii; format=flowed Hi all, I'm new to python and consequently mod_python but have discovered the servlet" package, and actually have a small templated webapp up and running. Extremely powerful language. I would like to be able to retrieve both _form_ and _query_ variables, even if they share the same name. e.g. <form method='post' action='/?name=NAME_ONE'> <input type='hidden' name='name' value='NAME_TWO' /> <input type='submit' /> </form> It seems that when both a GET and POST variable share the same name that the GET (query) variable always wins. Does anybody know how this might be accomplished? Thanks, Mike Wright ------------------------------ Message: 2 Date: Tue, 06 Jul 2004 08:43:36 +1000 From: Byron Ellacott <bje at apnic.net> Subject: Re: [mod_python] Does mod_python have a global dictionary or sorts? To: mod_python user mailing list <mod_python at modpython.org> Message-ID: <40E9D998.3060501 at apnic.net> Content-Type: text/plain; charset=us-ascii; format=flowed James Gate wrote: > I've started writing Web Applications using mod_python and was wondering > if there is some sort of global dictionary that I can register objects > in, similar in method to that of Java Servlets? What I'm trying to do is > create a global connection pool for database access, that is accessible > by all apache threads. I've written and tests a thread safe connection > pool, and just need somewhere to place an instance of it! (As long as you're running a threaded Apache, and not a forking Apache...) Just stick it in a global variable. You can make it a singleton instance easily enough: --- snip DBPool.py --- #!/usr/bin/env python class DBPool: pass pool = DBPool() --- snip DBPool.py --- mod_python reuses Python interpreters, so once your module has been loaded, any subsequent imports of it will just be obtaining a reference from sys.modules[]. You'll want to watch for how you've told mod_python to create interpreters; by default it creates one interpreter per process, but you can also tell it to create an interpreter per directory or a specifically named interpreter. -- bje ------------------------------ Message: 3 Date: Mon, 05 Jul 2004 21:57:05 -0400 From: Jorey Bump <list at joreybump.com> Subject: Re: [mod_python] query_vars and form_vars To: mod_python user mailing list <mod_python at modpython.org> Message-ID: <40EA06F1.3060401 at joreybump.com> Content-Type: text/plain; charset=us-ascii; format=flowed mod_python user wrote: > Hi all, > > I'm new to python and consequently mod_python but have discovered the > servlet" package, and actually have a small templated webapp up and > running. Extremely powerful language. > > I would like to be able to retrieve both _form_ and _query_ variables, > even if they share the same name. e.g. > > <form method='post' action='/?name=NAME_ONE'> > <input type='hidden' name='name' value='NAME_TWO' /> > <input type='submit' /> > </form> > > It seems that when both a GET and POST variable share the same name that > the GET (query) variable always wins. > > Does anybody know how this might be accomplished? I don't know about servlets, but mod_publisher returns a list: ['NAME_ONE', 'NAME_TWO'] I don't know what causes this behaviour. Since only a POST request is sent, not a GET, I would expect any arguments in the URL to be ignored and only variables in the message body to be recognized. I'd find out if this follows some kind of standard before relying on the order the values appear in a list. It could be arbitrary or undocumented (and therefore unpredictable). ------------------------------ Message: 4 Date: Tue, 06 Jul 2004 00:56:40 -0400 From: Jorey Bump <list at joreybump.com> Subject: Re: [mod_python] query_vars and form_vars To: mod_python user mailing list <mod_python at modpython.org> Message-ID: <40EA3108.8000009 at joreybump.com> Content-Type: text/plain; charset=us-ascii; format=flowed Jorey Bump wrote: > mod_python user wrote: > >> I would like to be able to retrieve both _form_ and _query_ >> variables, even if they share the same name. e.g. >> >> <form method='post' action='/?name=NAME_ONE'> <input type='hidden' >> name='name' value='NAME_TWO' /> <input type='submit' /> </form> >> >> It seems that when both a GET and POST variable share the same name >> that the GET (query) variable always wins. >> >> Does anybody know how this might be accomplished? > > I don't know about servlets, but mod_publisher returns a list: > > ['NAME_ONE', 'NAME_TWO'] Duh. I mean mod_python.publisher. :P > I don't know what causes this behaviour. Since only a POST request is > sent, not a GET, I would expect any arguments in the URL to be > ignored and only variables in the message body to be recognized. FWIW, mod_php ignores the URL arguments: Array ( [name] => NAME_TWO ) This seems more appropriate. A user shouldn't be allowed to mess with POST data so easily. If this gets fixed (assuming it's a bug), you can still use req.unparsed_uri and do your own parsing. For example, use publisher and create foo.py with this function: def test(req): return req.unparsed_uri Then view the results at: http://localhost/foo.py/test?name=something Extract whatever you want from the resulting string. ------------------------------ Message: 5 Date: Tue, 06 Jul 2004 15:43:38 +1000 From: Byron Ellacott <bje at apnic.net> Subject: Re: [mod_python] query_vars and form_vars To: mod_python user mailing list <mod_python at modpython.org> Message-ID: <40EA3C0A.4010608 at apnic.net> Content-Type: text/plain; charset=us-ascii; format=flowed Jorey Bump wrote: > I don't know what causes this behaviour. Since only a POST request is > sent, not a GET, I would expect any arguments in the URL to be ignored > and only variables in the message body to be recognized. The specification makes a distinction between URL encoded arguments (a query fragment) and POST data (just plain old data). The URL arguments form part of the resource request, and should be treated as effectively the same as a path fragment, that is, only used to specify which resource it is the user is requesting. POST data is misdefined in RFC2616 as "a new subordinate of" the requested resource, and corrected in http://purl.org/NET/http-errata to be "data processed by" the requested resource. So, in essence, the protocol definition makes a clear distinction between the roles of query fragments and POST data, but that distinction is lost when dealing with the vast bulk of web programming libraries out there, including mod_python's FieldStorage class. The correct (as-per-specification) behaviour would be to distinguish between query arguments and POST data values. It is quite easy to argue that long convention makes the specification's differentiation irrelevant, however. But in neither world should part of the URL be /ignored/. :) -- bje ------------------------------ Message: 6 Date: Tue, 06 Jul 2004 09:36:36 -0400 From: Jorey Bump <list at joreybump.com> Subject: Re: [mod_python] query_vars and form_vars To: mod_python user mailing list <mod_python at modpython.org> Message-ID: <40EAAAE4.1000709 at joreybump.com> Content-Type: text/plain; charset=us-ascii; format=flowed Byron Ellacott wrote: > Jorey Bump wrote: > >> I don't know what causes this behaviour. Since only a POST request is >> sent, not a GET, I would expect any arguments in the URL to be ignored >> and only variables in the message body to be recognized. > > > The specification makes a distinction between URL encoded arguments (a > query fragment) and POST data (just plain old data). The URL arguments > form part of the resource request, and should be treated as effectively > the same as a path fragment, that is, only used to specify which > resource it is the user is requesting. POST data is misdefined in > RFC2616 as "a new subordinate of" the requested resource, and corrected > in http://purl.org/NET/http-errata to be "data processed by" the > requested resource. > > So, in essence, the protocol definition makes a clear distinction > between the roles of query fragments and POST data, but that distinction > is lost when dealing with the vast bulk of web programming libraries out > there, including mod_python's FieldStorage class. The correct > (as-per-specification) behaviour would be to distinguish between query > arguments and POST data values. > > It is quite easy to argue that long convention makes the specification's > differentiation irrelevant, however. But in neither world should part > of the URL be /ignored/. :) Well, I didn't say /discarded/. :) Query parts shouldn't prevent access to a resource (unless desired), but is it even appropriate to return them in an array if the GET method wasn't explicitly used? To clarify my original statement: If the POST method is used, query parts in the URL should *not* be considered part of the form data set. This removes all ambiguity about precedence, substitution, or type conversion. RFC2616 doesn't prohibit passing arguments in a URI when submitting POST data, but nowhere does it say that they should be processed as form data or supersede any variables passed as POST data. I'd disagree that POST data was originally misdefined; I believe the author was thinking more in terms of scope, where the POST data served to extend a resource. Taken literally, it still doesn't imply that the query parts should be acted upon; they're simply part of the URI. I like the new language, however, because it's less ambiguous. ------------------------------ Message: 7 Date: Tue, 6 Jul 2004 09:45:35 -0400 From: "Daniel J. Popowich" <dpopowich at comcast.net> Subject: Re: [mod_python] query_vars and form_vars To: mod_python user mailing list <mod_python at modpython.org> Message-ID: <16618.44287.620236.878993 at gargle.gargle.HOWL> Content-Type: text/plain; charset=us-ascii mod_python user writes: > I'm new to python and consequently mod_python but have discovered the > servlet" package, and actually have a small templated webapp up and > running. Extremely powerful language. > > I would like to be able to retrieve both _form_ and _query_ variables, > even if they share the same name. e.g. > > <form method='post' action='/?name=NAME_ONE'> > <input type='hidden' name='name' value='NAME_TWO' /> > <input type='submit' /> > </form> > > It seems that when both a GET and POST variable share the same name that > the GET (query) variable always wins. > > Does anybody know how this might be accomplished? Since you're acquiring this data from a POST you will probably want to use form_vars instead of query_vars and set it like this: form_vars = [('name', [])] Setting form_vars this way tells the servlet handler to get the value of 'name' from the FieldStorage instance with the getlist method. Setting form_vars like this: form_vars = ['name'] tells the handler to retrieve 'name' using the getfirst method. Check out lesson #10 in the tutorial that comes with Mod_python Servlets for a discussion concerning retrieving lists. Lesson #12 discusses query_vars vs. form_vars. Daniel ------------------------------ Message: 8 Date: Tue, 6 Jul 2004 10:43:04 -0400 (EDT) From: "Gregory (Grisha) Trubetskoy" <grisha at modpython.org> Subject: Re: [mod_python] query_vars and form_vars To: mod_python user mailing list <mod_python at modpython.org> Message-ID: <20040706102719.O8523 at onyx.ispol.com> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed This behaviour is part of mod_python.util.FieldStorage class, which is a little convenience tool. Protocol compliance is of little or no relevance here, since you're free not to use it and process input data using your own code or, for example using Python standard library FieldStorage. Also, if I remember it correctly, most relevant RFC's tend to focus on the behaviour of the browser (e.g. the user should be warned before a POST if you hit reload, but not for GET), and there is nothing there about how the form variables should appear to an application. As to why it processes GET and POST together and GET wins - that's a matter of personal preference. I find it convenient to be able to override variables in a form by appending them to the URL, and I think most user-friendly applications should behave this way, because IMHO ability to tinker with the URL is a good thing. Some people believe that this should not be allowed because it enables a user to alter hidden POST variables, which would otherwise be difficult, but this seems to me like a silly argument. There are much more certain ways of ensuring that hidden variables have not been modified, e.g. an MD5 or SHA signature passed along. Grisha On Mon, 5 Jul 2004, Jorey Bump wrote: > mod_python user wrote: > >> Hi all, >> >> I'm new to python and consequently mod_python but have discovered the >> servlet" package, and actually have a small templated webapp up and >> running. Extremely powerful language. >> >> I would like to be able to retrieve both _form_ and _query_ variables, >> even if they share the same name. e.g. >> >> <form method='post' action='/?name=NAME_ONE'> >> <input type='hidden' name='name' value='NAME_TWO' /> >> <input type='submit' /> >> </form> >> >> It seems that when both a GET and POST variable share the same name that >> the GET (query) variable always wins. >> >> Does anybody know how this might be accomplished? > > I don't know about servlets, but mod_publisher returns a list: > > ['NAME_ONE', 'NAME_TWO'] > > I don't know what causes this behaviour. Since only a POST request is sent, > not a GET, I would expect any arguments in the URL to be ignored and only > variables in the message body to be recognized. > > I'd find out if this follows some kind of standard before relying on the > order the values appear in a list. It could be arbitrary or undocumented (and > therefore unpredictable). > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://mailman.modpython.org/mailman/listinfo/mod_python > ------------------------------ Message: 9 Date: Tue, 06 Jul 2004 08:55:32 -0600 From: Dan Olsen <python at dan-olsen.net> Subject: [mod_python] Version Compatibility To: mod_python at modpython.org Message-ID: <40EABD64.5020500 at dan-olsen.net> Content-Type: text/plain; charset="us-ascii" Does mod_python 2.7.10 work with Python 2.3.3? The prerequisites say that it should have Python 1.5.2, 1.6, 2.0 or 2.1. I tried to find something about it in the archives but couldn't find anything. Dan Olsen -------------- next part -------------- An HTML attachment was scrubbed... URL: http://modpython.org/pipermail/mod_python/attachments/20040706/216f7239/atta chment-0001.html ------------------------------ Message: 10 Date: Tue, 06 Jul 2004 08:59:44 -0700 From: John Riehl <jcriehl at mail.jpl.nasa.gov> Subject: [mod_python] erratic behaviour from mptest.py To: mod_python at modpython.org Message-ID: <40EACC70.4030504 at mail.jpl.nasa.gov> Content-Type: text/plain; charset=us-ascii; format=flowed I set up a textbook mptest.py "hello world" example. Sometimes it works, sometimes it gives me this: ---------------------------------------------------------------------- Mod_python error: "PythonHandler mptest" Traceback (most recent call last): File "/usr/lib/python2.2/site-packages/mod_python/apache.py", line 287, in HandlerDispatch log=debug) File "/usr/lib/python2.2/site-packages/mod_python/apache.py", line 457, in import_module module = imp.load_module(mname, f, p, d) File "/proj/simdev/www/modpython/mptest.py", line 1 from mod_python import apache ^ SyntaxError: invalid syntax --------------------------------------------------------------------- (---- are mine to delimit sections) To add to this, I created a second mptest.py, in a different location, which works all the time. (hello world). The flakey mptest.py is under the user's directories. The consistently correct one is under the apache document root, symlinked from the user directories (dont want to run this way). The flakey one seems to run correctly if I had just previously run the consistently correct one, or if it had just run correctly. If I wait a couple of minutes, and then run it, it will give me the error. Anyone seen this before? Any insight to resolving this? I have been reading the archives, and someone suggested replacing the PythonDebug On with <Files *> PythonPath "sys.path + ['/<pathname>/modpython']" PythonDebug On </Files> but that has not yielded any additional error information. apache error log has the same errors as above in it. mod_python is 3.1.3, apache is 2.0.49, and python is 2.2 (rpm: python-2.2.2-26). apache & mod_python were built from source, python is via rpm. Thanks in advance, jr john riehl sysadmin/mission systems engineer multi-mission information systems testbed jet propulsion laboratory ------------------------------ _______________________________________________ Mod_python mailing list Mod_python at modpython.org http://mailman.modpython.org/mailman/listinfo/mod_python End of Mod_python Digest, Vol 16, Issue 7 *****************************************
|