Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

routing: Transparently convert a MultiDict containing parameters. #724

Closed
wants to merge 3 commits into from

Conversation

houseofsuns
Copy link

@houseofsuns houseofsuns commented Apr 7, 2015

Sorry to nag once more w.r.t. the multiple values for URL building, but I think I found a way to make everybody happy. The following should allow passing in MultiDicts and receiving the desired behaviour without getting any regressions.
This should be ready to merge (as in there is test and documentation).

This allows to pass a MultiDict and get the intuitively expected result
(that is multiple parameters, where multiple values are present). This
allows to recreate a URL as follows:

  • create a URL with multiple values for a parameter
  • use Map.match() to extract them into a MultiDict
  • recreate the URL with Map.build() handing in the MultiDict

The last step would fail before this commit (in that it would reproduce only
one of the values for each parameter). Also this avoids the collateral
damage introduced by the last attempt at allowing MultiDicts.

This zaps one of the test cases in test_basic_building to reflect the
changed behaviour.

This allows to pass a MultiDict and get the intuitively expected result
(that is multiple parameters, where multiple values are present). This
allows to recreate a URL as follows:

* create a URL with multiple values for a parameter
* use Map.match() to extract them into a MultiDict
* recreate the URL with Map.build() handing in the MultiDict

The last step would fail before this commit (in that it would reproduce only
one of the values for each parameter). Also this avoids the collateral
damage introduced by the last attempt at allowing MultiDicts.

This zaps one of the test cases in test_basic_building to reflect the
changed behaviour.
@houseofsuns
Copy link
Author

Hm, I messed up the layout above ...

@untitaker
Copy link
Contributor

You can pass in multiple query params by providing a list of values as value. Isn't that good enough?

@houseofsuns
Copy link
Author

I have no strong feelings here, but I found the point that build() is then inverse to match() a big plus. For me this is more an enhancement/sugar coating so that everything works as I would intuitively expect it.

Also if not this change, I will have to modify some of my code to use lists of values, so I thought I might try here first, for the benefit of the general public. :)

Dict comprehension was added in 2.7, so we instead use a constructor.
@houseofsuns
Copy link
Author

I just saw the failure and fixed the syntax to be compatible to 2.6

valueiter = iteritems(values, multi=True)
temp = dict(
(k, (values.getlist(k)
if len(values.getlist(k)) > 1

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This uses a more explicit version than the more elegant comprehension to get
rid of the duplicate getlist call.
@houseofsuns
Copy link
Author

Tentative bump. What about this, it looks like I'll actually not need this anymore, but I think it would be a sensible change anyway. :)

@edk0 edk0 mentioned this pull request Apr 20, 2018
@davidism
Copy link
Member

Issue history so I can keep this straight:

@davidism
Copy link
Member

Continued in #1310

@davidism davidism closed this May 22, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants