def _urlunsplit(scheme=None, netloc=None, path=None, query=None,
fragment=None):
"""Like ``urlparse.urlunsplit``, but will escape values and urlencode and
sort query arguments.
:param scheme:
URI scheme, e.g., `http` or `https`.
:param netloc:
Network location, e.g., `localhost:8080` or `www.google.com`.
:param path:
URI path.
:param query:
URI query as an escaped string, or a dictionary or list of key-values
tuples to build a query.
:param fragment:
Fragment identifier, also known as "anchor".
:returns:
An assembled absolute or relative URI.
"""
if not scheme or not netloc:
scheme = ''
netloc = None
if path:
path = quote(_to_utf8(path))
if query and not isinstance(query, six.string_types):
if isinstance(query, dict):
query = six.iteritems(query)
# Sort args: commonly needed to build signatures for services.
query = urlencode(sorted(query))
if fragment:
fragment = quote(_to_utf8(fragment))
return urlunsplit((scheme, netloc, path, query, fragment))
评论列表
文章目录