MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / quote_plus

Function quote_plus

tools/python-3.11.9-amd64/Lib/urllib/parse.py:901–916  ·  view source on GitHub ↗

Like quote(), but also replace ' ' with '+', as required for quoting HTML form values. Plus signs in the original string are escaped unless they are included in safe. It also does not have safe default to '/'.

(string, safe='', encoding=None, errors=None)

Source from the content-addressed store, hash-verified

899 return quote_from_bytes(string, safe)
900
901def quote_plus(string, safe='', encoding=None, errors=None):
902 """Like quote(), but also replace ' ' with '+', as required for quoting
903 HTML form values. Plus signs in the original string are escaped unless
904 they are included in safe. It also does not have safe default to '/'.
905 """
906 # Check if ' ' in string, where string may either be a str or bytes. If
907 # there are no spaces, the regular quote will produce the right answer.
908 if ((isinstance(string, str) and ' ' not in string) or
909 (isinstance(string, bytes) and b' ' not in string)):
910 return quote(string, safe, encoding, errors)
911 if isinstance(safe, str):
912 space = ' '
913 else:
914 space = b' '
915 string = quote(string, safe + space, encoding, errors)
916 return string.replace(' ', '+')
917
918# Expectation: A typical program is unlikely to create more than 5 of these.
919@functools.lru_cache

Callers

nothing calls this directly

Calls 2

quoteFunction · 0.70
replaceMethod · 0.45

Tested by

no test coverage detected