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

Add convenience / utility methods to urllib.parse's structured result objects #96381

Open
xmo-odoo opened this issue Aug 29, 2022 · 0 comments
Open
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@xmo-odoo
Copy link

Currently, non-trivial URL manipulations require going back and forth between structured results and utility functions in order to process or manipulate the URL in non-trivial ways (other than entirely replacing one of the attributes).

werkzeug.urls (which started as a cross-version compatibility shim) shows a few utility properties and methods:

  • join, which performs a Resutl -> Result urljoin
  • decode_query, which performs a parse_qs (-l, kind-of, as werkzeug uses multidicts)
  • ascii_host, which return a punycode/idna-encoded domain if necessary
  • auth, which returns the encoded userinfo

The first three are commonly useful, and require a fair amount of syntactic overhead to perform using the stdlib. The 4th would mostly be solved by making _userinfo public / stable and documenting it, though a purely textual version could also be useful.

One utility which I think is missing from werkzeug and would also be useful is a shortcut to set/update query string parameters directly, which IME is quite common: looking at a pretty url-heavy codebase, 20~30% of the querystring manipulations are straighforward set-and-forget (the rest is lookups, with a few odd more complicated manipulations of the query string which do need to fully decode and process the result).

As urllib.parse already layers a few mixins on top of the base namedtuples, I don't think this would incur significant runtime costs (the helpers could probably be added to existing mixins)

@xmo-odoo xmo-odoo added the type-feature A feature request or enhancement label Aug 29, 2022
@iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants