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)
| 899 | return quote_from_bytes(string, safe) |
| 900 | |
| 901 | def 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 |