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)
| 556 | # comparison since this API supports both bytes and str input. |
| 557 | @functools.lru_cache(typed=True) |
| 558 | def 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 | |
| 593 | def _urlsplit(url, scheme=None, allow_fragments=True): |
| 594 | # Only lstrip url as some applications rely on preserving trailing space. |
searching dependent graphs…