[mod_python] .value in FieldStorage

Markus Demleitner msdemlei at cl.uni-heidelberg.de
Wed Apr 17 20:55:12 EST 2002


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]
            return StringWithValue(found[0])
          return found

This is of course super-ugly and will break when someone updates

Is FieldStorage's behaviour again due to my stupidity?  If not,
are there any plans to change it so it always returns Fields?



More information about the Mod_python mailing list