[mod_python] .value in FieldStorage

Gregory (Grisha) Trubetskoy grisha at modpython.org
Wed Apr 17 16:39:35 EST 2002


Markus -

The rationale is that not everyone using mod_python is migrating from CGI.
For those of us who are writing mod_python handlers from scratch having to
use .value all over the place seemed like an annoyance.

Rather than patching mod_python code, I suggest either subclassing
FieldStorage, or using cgi.FieldStorage.

Grisha

On Wed, 17 Apr 2002, Markus Demleitner wrote:

> Hi,
>
> I'm again working on my project of migrating from CGI to mod_python.
> This time, it's FieldStorage.  For some reason, FieldStorage.__getitem__
> may return strings instead of fields.  When you want to keep your
> classes compatible with cgi's FieldStorage, that's of course a
> major showstopper, since every access to the value attribute
> raises an exception.
>
> As an emergency patch (I needed to get this done, since some
> gadget of mine was causing excessive server loads when it
> didn't need to), I added
>
> import UserString
>
> class StringWithValue(UserString.UserString):
>   def __init__(self, val):
>     UserString.UserString.__init__(self, val)
>     self.value = val
>
> at the top of util.py and changed then end of FieldStorage's
> __getitem__ to
>         if len(found) == 1:
>           if isinstance(found[0], Field):
>             return found[0]
>           else:
>             return StringWithValue(found[0])
>         else:
>           return found
>
>
> This is of course super-ugly and will break when someone updates
> mod_python.
>
> Is FieldStorage's behaviour again due to my stupidity?  If not,
> are there any plans to change it so it always returns Fields?
>
> Cheers,
>
>        Markus
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://www.modpython.org/mailman/listinfo/mod_python
>




More information about the Mod_python mailing list