MCPcopy Index your code
hub / github.com/python/cpython / urlunparse

Function urlunparse

Lib/urllib/parse.py:627–654  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

625 return (scheme, netloc, url, query, fragment)
626
627def 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
656def urlunsplit(components, *, keep_empty=_UNSPECIFIED):
657 """Combine the elements of a tuple as returned by urlsplit() into a

Callers 4

checkRoundtripsMethod · 0.90
checkRoundtrips1Method · 0.90
http_error_302Method · 0.90
geturlMethod · 0.85

Calls 2

_coerce_argsFunction · 0.85
_urlunsplitFunction · 0.85

Tested by 2

checkRoundtripsMethod · 0.72
checkRoundtrips1Method · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…