Put a parsed URL back together again. This may result in a slightly different, but equivalent URL, if the URL that was parsed originally had redundant delimiters, e.g. a ? with an empty query (the draft states that these are equivalent) and keep_empty is false or components is the r
(components, *, keep_empty=_UNSPECIFIED)
| 625 | return (scheme, netloc, url, query, fragment) |
| 626 | |
| 627 | def urlunparse(components, *, keep_empty=_UNSPECIFIED): |
| 628 | """Put a parsed URL back together again. This may result in a |
| 629 | slightly different, but equivalent URL, if the URL that was parsed |
| 630 | originally had redundant delimiters, e.g. a ? with an empty query |
| 631 | (the draft states that these are equivalent) and keep_empty is false |
| 632 | or components is the result of the urlparse() call with |
| 633 | missing_as_none=False.""" |
| 634 | scheme, netloc, url, params, query, fragment, _coerce_result = ( |
| 635 | _coerce_args(*components)) |
| 636 | if keep_empty is _UNSPECIFIED: |
| 637 | keep_empty = getattr(components, '_keep_empty', _MISSING_AS_NONE_DEFAULT) |
| 638 | elif keep_empty and not getattr(components, '_keep_empty', True): |
| 639 | raise ValueError('Cannot distinguish between empty and not defined ' |
| 640 | 'URI components in the result of parsing URL with ' |
| 641 | 'missing_as_none=False') |
| 642 | if not keep_empty: |
| 643 | if not netloc: |
| 644 | if scheme and scheme in uses_netloc and (not url or url[:1] == '/'): |
| 645 | netloc = '' |
| 646 | else: |
| 647 | netloc = None |
| 648 | if not scheme: scheme = None |
| 649 | if not params: params = None |
| 650 | if not query: query = None |
| 651 | if not fragment: fragment = None |
| 652 | if params is not None: |
| 653 | url = "%s;%s" % (url, params) |
| 654 | return _coerce_result(_urlunsplit(scheme, netloc, url, query, fragment)) |
| 655 | |
| 656 | def urlunsplit(components, *, keep_empty=_UNSPECIFIED): |
| 657 | """Combine the elements of a tuple as returned by urlsplit() into a |
searching dependent graphs…