def dict2query(dictionary):
query = []<EOL>encoders = {dict: _dictionary_encoder}<EOL>for k, v in dictionary.iteritems():<EOL><INDENT>if v.__class__ in encoders:<EOL><INDENT>nested_query = encoders[v.__class__](k, v)<EOL>query += nested_query<EOL><DEDENT>else:<EOL><INDENT>key = to_utf8(k)<EOL>value = to_utf8(v)<EOL>query.append('<STR_LIT>'.format(key, value))<EOL><DEDENT><DEDENT>return '<STR_LIT:&>'.join(query)<EOL>
We want post vars of form:
{'foo': 'bar', 'nested': {'a': 'b', 'c': 'd'}}
to become:
foo=bar&nested[a]=b&nested[c]=d