351 flattened to {'a[0]': 'b', 'a[1]': 'c', 'd[e]': 'f'} and then passed to |
351 flattened to {'a[0]': 'b', 'a[1]': 'c', 'd[e]': 'f'} and then passed to |
352 urlencode. Note: the encoding is consistent with PHP's http_build_query. |
352 urlencode. Note: the encoding is consistent with PHP's http_build_query. |
353 """ |
353 """ |
354 flatparams = util.sortdict() |
354 flatparams = util.sortdict() |
355 |
355 |
356 def process(prefix, obj): |
356 def process(prefix: bytes, obj): |
357 if isinstance(obj, bool): |
357 if isinstance(obj, bool): |
358 obj = {True: b'true', False: b'false'}[obj] # Python -> PHP form |
358 obj = {True: b'true', False: b'false'}[obj] # Python -> PHP form |
359 lister = lambda l: [(b'%d' % k, v) for k, v in enumerate(l)] |
359 lister = lambda l: [(b'%d' % k, v) for k, v in enumerate(l)] |
|
360 # .items() will only be called for a dict type |
|
361 # pytype: disable=attribute-error |
360 items = {list: lister, dict: lambda x: x.items()}.get(type(obj)) |
362 items = {list: lister, dict: lambda x: x.items()}.get(type(obj)) |
|
363 # pytype: enable=attribute-error |
361 if items is None: |
364 if items is None: |
362 flatparams[prefix] = obj |
365 flatparams[prefix] = obj |
363 else: |
366 else: |
364 for k, v in items(obj): |
367 for k, v in items(obj): |
365 if prefix: |
368 if prefix: |