Loading...

mod_python@modpython.org

[Prev] Thread [Next]  |  [Prev] Date [Next]

Re: [mod_python] using FieldStorage without publishing handler Nic James Ferrier Fri Apr 20 12:06:28 2007

"Ruben K." <[EMAIL PROTECTED]> writes:

> Hello,
>
> I was wondering if it is possible to use FieldStorage for POST data and FILE
> data
> without having to use the publishing handler. Is it possible? How would I go
> about this?
>
> The only kind of data I have been able to get with it is GET data

I think you must be doing something wrong because it just works:

  def handler(http):
      params = util.FieldStorage(http)
      for field in params.list:
          print >>http, 
               """<span class="%s">%s</span>""" %
                       (field.name, field.value)

will spit out some values with GET or POST.

It seems to prefer either one of the URI args or the
multipart/form-data args so if you're doing this:

  POST /someuri?name=value
  content-type: application/x-www-form-urlencoded
  other=value

then you need to have something combines the two.

I use this:

  def http_params(http):
      mod_python_form = util.FieldStorage(http)
      fields = mod_python_form.list
      result_dict = {}
      try:
          result_dict = util.parse_qs(http.args, True)
      except TypeError:
          # The above can produce an error coz http.args is None
          pass

      for field in fields:
          result_dict[field.name] = field.value
      return result_dict

But this also normalizes the fielstorage to a normal dict and I
suspect there is more elegant python that will do the job much better.

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   
_______________________________________________
Mod_python mailing list
[EMAIL PROTECTED]
http://mailman.modpython.org/mailman/listinfo/mod_python