quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Graham Dumpleton (JIRA)" <j...@apache.org>
Subject [jira] Commented: (MODPYTHON-93) Improve util.FieldStorage efficiency
Date Sun, 29 Oct 2006 07:49:17 GMT
    [ http://issues.apache.org/jira/browse/MODPYTHON-93?page=comments#action_12445435 ] 
Graham Dumpleton commented on MODPYTHON-93:

Okay, bit the bullet and made FieldStorage a bit more dictionary like after a bit of discussion
on the mailing lists by adding __setitem__(), __delitem__(), __iter__(), __repr__() and clear()
on top of other dictionary like methods it already had. To say it is dictionary like is probably
only true though for the case where there is a single value against all form fields. Once
you start having multiple values against a form field it starts to behave a bit differently.
That it isn't strictly the same has been documented.

First difference is that subscript operator when used to access fields returns the actual
value when there is only one, but a list of values when there is more than one. To always
ensure one only gets a single value, should use getfirst(), if always a list, use getlist()
instead. The way the subscript operator behaves is the same as cgi.FieldStorage so not doing
anything different here.

Second difference is that subscript operator when used to set the value of a field actually
adds the value to an existing value if one already exists. In other words, it does not replace
the existing value but adds another. This is because it uses add_field(). There is no equivalent
in cgi.FieldStorage, but this behaviour is consistent with how Trac was overriding the class
and providing its own __setitem__() method. If one really wants to supplant an existing value,
should use del operator first to remove existing values.

So there is some strangeness in how it works. If anyone specifically sees a big problem with
the __setitem__() method and how it works, speak up.

> Improve util.FieldStorage efficiency
> ------------------------------------
>                 Key: MODPYTHON-93
>                 URL: http://issues.apache.org/jira/browse/MODPYTHON-93
>             Project: mod_python
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 3.2.7
>            Reporter: Jim Gallacher
>         Assigned To: Graham Dumpleton
>            Priority: Minor
>             Fix For: 3.3
>         Attachments: modpython325_util_py_dict.patch
> Form fields are saved as a list in a FieldStorage class instance. The class implements
a __getitem__ method to provide dict-like behaviour.  This method iterates over the complete
list for every call to __getitem__. Applications that need to access all the fields when processing
the form will show O(n^2) behaviour where n == the number of form fields. This overhead could
be avoided by creating a dict (to use as an index) when the FieldStorage instance is created.
> Mike Looijmans has been investigating StringField and Field as well. It is probably reasonable
to include information on his work in this issue as well, so that we can consider all of these
efficiency issues in toto.

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


View raw message