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

Function requote_uri

src/requests/utils.py:704–723  ·  view source on GitHub ↗

Re-quote the given URI. This function passes the given URI through an unquote/quote cycle to ensure that it is fully and consistently quoted. :rtype: str

(uri: str)

Source from the content-addressed store, hash-verified

702
703
704def requote_uri(uri: str) -> str:
705 """Re-quote the given URI.
706
707 This function passes the given URI through an unquote/quote cycle to
708 ensure that it is fully and consistently quoted.
709
710 :rtype: str
711 """
712 safe_with_percent = "!#$%&'()*+,/:;=?@[]~"
713 safe_without_percent = "!#$&'()*+,/:;=?@[]~"
714 try:
715 # Unquote only the unreserved characters
716 # Then quote only illegal characters (do not quote reserved,
717 # unreserved, or '%')
718 return quote(unquote_unreserved(uri), safe=safe_with_percent)
719 except InvalidURL:
720 # We couldn't unquote the given URI, so let's try quoting it, but
721 # there may be unquoted '%'s in the URI. We need to make sure they're
722 # properly quoted so they do not cause issues elsewhere.
723 return quote(uri, safe=safe_without_percent)
724
725
726def address_in_network(ip: str, net: str) -> bool:

Callers 3

prepare_urlMethod · 0.85
resolve_redirectsMethod · 0.85

Calls 1

unquote_unreservedFunction · 0.85

Tested by 1