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

Function _unquote_impl

Lib/urllib/parse.py:795–822  ·  view source on GitHub ↗
(string: bytes | bytearray | str)

Source from the content-addressed store, hash-verified

793 return bytes(_unquote_impl(string))
794
795def _unquote_impl(string: bytes | bytearray | str) -> bytes | bytearray:
796 # Note: strings are encoded as UTF-8. This is only an issue if it contains
797 # unescaped non-ASCII characters, which URIs should not.
798 if not string:
799 # Is it a string-like object?
800 string.split
801 return b''
802 if isinstance(string, str):
803 string = string.encode('utf-8')
804 bits = string.split(b'%')
805 if len(bits) == 1:
806 return string
807 res = bytearray(bits[0])
808 append = res.extend
809 # Delay the initialization of the table to not waste memory
810 # if the function is never called
811 global _hextobyte
812 if _hextobyte is None:
813 _hextobyte = {(a + b).encode(): bytes.fromhex(a + b)
814 for a in _hexdig for b in _hexdig}
815 for item in bits[1:]:
816 try:
817 append(_hextobyte[item[:2]])
818 append(item[2:])
819 except KeyError:
820 append(b'%')
821 append(item)
822 return res
823
824_asciire = re.compile('([\x00-\x7f]+)')
825

Callers 3

unquote_to_bytesFunction · 0.85
_generate_unquoted_partsFunction · 0.85
unquoteFunction · 0.85

Calls 2

encodeMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…