Updates a URI with new query parameters. If a given key from ``params`` is repeated in the ``uri``, then the URI will be considered invalid and an error will occur. If the URI is valid, then each value from ``params`` will replace the corresponding value in the query parameters (if
(uri, params)
| 164 | |
| 165 | |
| 166 | def update_query_params(uri, params): |
| 167 | """Updates a URI with new query parameters. |
| 168 | |
| 169 | If a given key from ``params`` is repeated in the ``uri``, then |
| 170 | the URI will be considered invalid and an error will occur. |
| 171 | |
| 172 | If the URI is valid, then each value from ``params`` will |
| 173 | replace the corresponding value in the query parameters (if |
| 174 | it exists). |
| 175 | |
| 176 | Args: |
| 177 | uri: string, A valid URI, with potential existing query parameters. |
| 178 | params: dict, A dictionary of query parameters. |
| 179 | |
| 180 | Returns: |
| 181 | The same URI but with the new query parameters added. |
| 182 | """ |
| 183 | parts = urllib.parse.urlparse(uri) |
| 184 | query_params = parse_unique_urlencoded(parts.query) |
| 185 | query_params.update(params) |
| 186 | new_query = urllib.parse.urlencode(query_params) |
| 187 | new_parts = parts._replace(query=new_query) |
| 188 | return urllib.parse.urlunparse(new_parts) |
| 189 | |
| 190 | |
| 191 | def _add_query_parameter(url, name, value): |
no test coverage detected
searching dependent graphs…