Get parameters as list of tuples, formatting collections. :param params: Parameters as dict or list of two-tuples :param dict collection_formats: Parameter collection formats :return: Parameters as list of tuples, collections formatted
(self, params, collection_formats)
| 452 | ) |
| 453 | |
| 454 | def parameters_to_tuples(self, params, collection_formats): |
| 455 | """Get parameters as list of tuples, formatting collections. |
| 456 | |
| 457 | :param params: Parameters as dict or list of two-tuples |
| 458 | :param dict collection_formats: Parameter collection formats |
| 459 | :return: Parameters as list of tuples, collections formatted |
| 460 | """ |
| 461 | new_params = [] |
| 462 | if collection_formats is None: |
| 463 | collection_formats = {} |
| 464 | for k, v in six.iteritems(params) if isinstance(params, dict) else params: # noqa: E501 |
| 465 | if k in collection_formats: |
| 466 | collection_format = collection_formats[k] |
| 467 | if collection_format == 'multi': |
| 468 | new_params.extend((k, value) for value in v) |
| 469 | else: |
| 470 | if collection_format == 'ssv': |
| 471 | delimiter = ' ' |
| 472 | elif collection_format == 'tsv': |
| 473 | delimiter = '\t' |
| 474 | elif collection_format == 'pipes': |
| 475 | delimiter = '|' |
| 476 | else: # csv is the default |
| 477 | delimiter = ',' |
| 478 | new_params.append( |
| 479 | (k, delimiter.join(str(value) for value in v))) |
| 480 | else: |
| 481 | new_params.append((k, v)) |
| 482 | return new_params |
| 483 | |
| 484 | def files_parameters(self, files=None): |
| 485 | """Builds form parameters. |