def transform(params):
for key, value in list(params.items()):<EOL><INDENT>if value is None:<EOL><INDENT>params.pop(key)<EOL>continue<EOL><DEDENT>if isinstance(value, (string_type, binary_type)):<EOL><INDENT>continue<EOL><DEDENT>if isinstance(value, integer_types):<EOL><INDENT>params[key] = text_type(value)<EOL><DEDENT>elif isinstance(value, (list, tuple, set, dict)):<EOL><INDENT>if not value:<EOL><INDENT>params.pop(key)<EOL><DEDENT>else:<EOL><INDENT>if isinstance(value, dict):<EOL><INDENT>value = [value]<EOL><DEDENT>if isinstance(value, set):<EOL><INDENT>value = list(value)<EOL><DEDENT>if not isinstance(value[<NUM_LIT:0>], dict):<EOL><INDENT>params[key] = "<STR_LIT:U+002C>".join(value)<EOL><DEDENT>else:<EOL><INDENT>params.pop(key)<EOL>for index, val in enumerate(value):<EOL><INDENT>for name, v in val.items():<EOL><INDENT>k = "<STR_LIT>" % (key, index, name)<EOL>params[k] = text_type(v)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError(type(value))<EOL><DEDENT><DEDENT>
Transforms an heterogeneous map of params into a CloudStack
ready mapping of parameter to values.

It handles lists and dicts.

>>> p = {"a": 1, "b": "foo", "c": ["eggs", "spam"], "d": {"key": "value"}}
>>> transform(p)
>>> print(p)
{'a': '1', 'b': 'foo', 'c': 'eggs,spam', 'd[0].key': 'value'}