MCPcopy
hub / github.com/psf/requests / unquote_unreserved

Function unquote_unreserved

src/requests/utils.py:680–701  ·  view source on GitHub ↗

Un-escape any percent-escape sequences in a URI that are unreserved characters. This leaves all reserved, illegal and non-ASCII bytes encoded. :rtype: str

(uri: str)

Source from the content-addressed store, hash-verified

678
679
680def unquote_unreserved(uri: str) -> str:
681 """Un-escape any percent-escape sequences in a URI that are unreserved
682 characters. This leaves all reserved, illegal and non-ASCII bytes encoded.
683
684 :rtype: str
685 """
686 parts = uri.split("%")
687 for i in range(1, len(parts)):
688 h = parts[i][0:2]
689 if len(h) == 2 and h.isalnum():
690 try:
691 c = chr(int(h, 16))
692 except ValueError:
693 raise InvalidURL(f"Invalid percent-escape sequence: '{h}'")
694
695 if c in UNRESERVED_SET:
696 parts[i] = c + parts[i][2:]
697 else:
698 parts[i] = f"%{parts[i]}"
699 else:
700 parts[i] = f"%{parts[i]}"
701 return "".join(parts)
702
703
704def requote_uri(uri: str) -> str:

Callers 2

test_unquote_unreservedFunction · 0.90
requote_uriFunction · 0.85

Calls 1

InvalidURLClass · 0.85

Tested by 1

test_unquote_unreservedFunction · 0.72