Search code examples
pythonjsonpyramid

decoding pyramid POST data (MultiDict Object)


I am receiving a POST request with data formatted as a MultiDict Object. Where can I find documentation about this data structure? and what is the best method (library) to decode these data into a dictionary object (with lists and dictionaries inside)

I did find this, in urllib3, but not sure if that's the. preferred way.

I already have written most of the code to match this style of data, so not really looking forward to changing the way the data is sent from the HTML form itself.

Thank you


Solution

  • MultiDict is part of the WebOb project, see it's MultiDict documenation.

    A MultiDict acts mostly just like a python dictionary, except that you can explicitly ask for one value or for a list of values with the .getone() and .getall() methods.

    .mixed() returns a dictionary with single and list values as needed to represent each key, or you can use .dict_of_lists() to produce lists for all keys.