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

Function quote_plus

Lib/urllib/parse.py:1074–1089  ·  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

1072 return quote_from_bytes(string, safe)
1073
1074def quote_plus(string, safe='', encoding=None, errors=None):
1075 """Like quote(), but also replace ' ' with '+', as required for quoting
1076 HTML form values. Plus signs in the original string are escaped unless
1077 they are included in safe. It also does not have safe default to '/'.
1078 """
1079 # Check if ' ' in string, where string may either be a str or bytes. If
1080 # there are no spaces, the regular quote will produce the right answer.
1081 if ((isinstance(string, str) and ' ' not in string) or
1082 (isinstance(string, bytes) and b' ' not in string)):
1083 return quote(string, safe, encoding, errors)
1084 if isinstance(safe, str):
1085 space = ' '
1086 else:
1087 space = b' '
1088 string = quote(string, safe + space, encoding, errors)
1089 return string.replace(' ', '+')
1090
1091# Expectation: A typical program is unlikely to create more than 5 of these.
1092@functools.lru_cache

Callers

nothing calls this directly

Calls 2

quoteFunction · 0.70
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…