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

Function urldefrag

Lib/urllib/parse.py:769–786  ·  view source on GitHub ↗

Removes any existing fragment from URL. Returns a tuple of the defragmented URL and the fragment. If the URL contained no fragments, the second element is the empty string or None if missing_as_none is True.

(url, *, missing_as_none=_MISSING_AS_NONE_DEFAULT)

Source from the content-addressed store, hash-verified

767
768
769def urldefrag(url, *, missing_as_none=_MISSING_AS_NONE_DEFAULT):
770 """Removes any existing fragment from URL.
771
772 Returns a tuple of the defragmented URL and the fragment. If
773 the URL contained no fragments, the second element is the
774 empty string or None if missing_as_none is True.
775 """
776 url, _coerce_result = _coerce_args(url)
777 if '#' in url:
778 s, n, p, q, frag = _urlsplit(url)
779 defrag = _urlunsplit(s, n, p, q, None)
780 else:
781 frag = None
782 defrag = url
783 if not missing_as_none and frag is None: frag = ''
784 result = _coerce_result(DefragResult(defrag, frag))
785 result._keep_empty = missing_as_none
786 return result
787
788_hexdig = '0123456789ABCDEFabcdef'
789_hextobyte = None

Callers 1

Calls 4

_coerce_argsFunction · 0.85
_urlsplitFunction · 0.85
_urlunsplitFunction · 0.85
DefragResultClass · 0.85

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…