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

Function urlsplit

Lib/urllib/parse.py:558–591  ·  view source on GitHub ↗

Parse a URL into 5 components: :// / ? # The result is a named 5-tuple with fields corresponding to the above. It is either a SplitResult or SplitResultBytes object, depending on the type of the url parameter. The username, password, hostname

(url, scheme=None, allow_fragments=True, *, missing_as_none=_MISSING_AS_NONE_DEFAULT)

Source from the content-addressed store, hash-verified

556# comparison since this API supports both bytes and str input.
557@functools.lru_cache(typed=True)
558def urlsplit(url, scheme=None, allow_fragments=True, *, missing_as_none=_MISSING_AS_NONE_DEFAULT):
559 """Parse a URL into 5 components:
560 <scheme>://<netloc>/<path>?<query>#<fragment>
561
562 The result is a named 5-tuple with fields corresponding to the
563 above. It is either a SplitResult or SplitResultBytes object,
564 depending on the type of the url parameter.
565
566 The username, password, hostname, and port sub-components of netloc
567 can also be accessed as attributes of the returned object.
568
569 The scheme argument provides the default value of the scheme
570 component when no scheme is found in url.
571
572 If allow_fragments is False, no attempt is made to separate the
573 fragment component from the previous component, which can be either
574 path or query.
575
576 Note that % escapes are not expanded.
577 """
578
579 url, scheme, _coerce_result = _coerce_args(url, scheme)
580 if url is None:
581 url = ''
582 scheme, netloc, url, query, fragment = _urlsplit(url, scheme, allow_fragments)
583 if not missing_as_none:
584 if scheme is None: scheme = ''
585 if netloc is None: netloc = ''
586 if query is None: query = ''
587 if fragment is None: fragment = ''
588 result = SplitResult(scheme, netloc, url, query, fragment)
589 result = _coerce_result(result)
590 result._keep_empty = missing_as_none
591 return result
592
593def _urlsplit(url, scheme=None, allow_fragments=True):
594 # Only lstrip url as some applications rely on preserving trailing space.

Callers 9

putrequestMethod · 0.90
test_fileMethod · 0.90
test_full_url_setterMethod · 0.90
checkRoundtripsMethod · 0.90
checkRoundtrips1Method · 0.90
checkJoinMethod · 0.90
reduce_uriMethod · 0.90
url2pathnameFunction · 0.90

Calls 3

_coerce_argsFunction · 0.85
_urlsplitFunction · 0.85
SplitResultClass · 0.85

Tested by 6

test_fileMethod · 0.72
test_full_url_setterMethod · 0.72
checkRoundtripsMethod · 0.72
checkRoundtrips1Method · 0.72
checkJoinMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…