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

Function _urlsplit

Lib/urllib/parse.py:593–625  ·  view source on GitHub ↗
(url, scheme=None, allow_fragments=True)

Source from the content-addressed store, hash-verified

591 return result
592
593def _urlsplit(url, scheme=None, allow_fragments=True):
594 # Only lstrip url as some applications rely on preserving trailing space.
595 # (https://url.spec.whatwg.org/#concept-basic-url-parser would strip both)
596 url = url.lstrip(_WHATWG_C0_CONTROL_OR_SPACE)
597 for b in _UNSAFE_URL_BYTES_TO_REMOVE:
598 url = url.replace(b, "")
599 if scheme is not None:
600 scheme = scheme.strip(_WHATWG_C0_CONTROL_OR_SPACE)
601 for b in _UNSAFE_URL_BYTES_TO_REMOVE:
602 scheme = scheme.replace(b, "")
603
604 allow_fragments = bool(allow_fragments)
605 netloc = query = fragment = None
606 i = url.find(':')
607 if i > 0 and url[0].isascii() and url[0].isalpha():
608 for c in url[:i]:
609 if c not in scheme_chars:
610 break
611 else:
612 scheme, url = url[:i].lower(), url[i+1:]
613 if url[:2] == '//':
614 netloc, url = _splitnetloc(url, 2)
615 if (('[' in netloc and ']' not in netloc) or
616 (']' in netloc and '[' not in netloc)):
617 raise ValueError("Invalid IPv6 URL")
618 if '[' in netloc and ']' in netloc:
619 _check_bracketed_netloc(netloc)
620 if allow_fragments and '#' in url:
621 url, fragment = url.split('#', 1)
622 if '?' in url:
623 url, query = url.split('?', 1)
624 _checknetloc(netloc)
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

Callers 4

_urlparseFunction · 0.85
urlsplitFunction · 0.85
urljoinFunction · 0.85
urldefragFunction · 0.85

Calls 11

_splitnetlocFunction · 0.85
_check_bracketed_netlocFunction · 0.85
_checknetlocFunction · 0.85
isasciiMethod · 0.80
isalphaMethod · 0.80
lstripMethod · 0.45
replaceMethod · 0.45
stripMethod · 0.45
findMethod · 0.45
lowerMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…