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='', allow_fragments=True)
| 471 | # comparison since this API supports both bytes and str input. |
| 472 | @functools.lru_cache(typed=True) |
| 473 | def urlsplit(url, scheme='', allow_fragments=True): |
| 474 | """Parse a URL into 5 components: |
| 475 | <scheme>://<netloc>/<path>?<query>#<fragment> |
| 476 | |
| 477 | The result is a named 5-tuple with fields corresponding to the |
| 478 | above. It is either a SplitResult or SplitResultBytes object, |
| 479 | depending on the type of the url parameter. |
| 480 | |
| 481 | The username, password, hostname, and port sub-components of netloc |
| 482 | can also be accessed as attributes of the returned object. |
| 483 | |
| 484 | The scheme argument provides the default value of the scheme |
| 485 | component when no scheme is found in url. |
| 486 | |
| 487 | If allow_fragments is False, no attempt is made to separate the |
| 488 | fragment component from the previous component, which can be either |
| 489 | path or query. |
| 490 | |
| 491 | Note that % escapes are not expanded. |
| 492 | """ |
| 493 | |
| 494 | url, scheme, _coerce_result = _coerce_args(url, scheme) |
| 495 | scheme, netloc, url, query, fragment = _urlsplit(url, scheme, allow_fragments) |
| 496 | v = SplitResult(scheme or '', netloc or '', url, query or '', fragment or '') |
| 497 | return _coerce_result(v) |
| 498 | |
| 499 | def _urlsplit(url, scheme=None, allow_fragments=True): |
| 500 | # Only lstrip url as some applications rely on preserving trailing space. |