Returns a URL-encoded version of the given value. If ``plus`` is true (the default), spaces will be represented as "+" instead of "%20". This is appropriate for query strings but not for the path component of a URL. Note that this default is the reverse of Python's urllib module.
(value: Union[str, bytes], plus: bool = True)
| 89 | |
| 90 | |
| 91 | def url_escape(value: Union[str, bytes], plus: bool = True) -> str: |
| 92 | """Returns a URL-encoded version of the given value. |
| 93 | |
| 94 | If ``plus`` is true (the default), spaces will be represented |
| 95 | as "+" instead of "%20". This is appropriate for query strings |
| 96 | but not for the path component of a URL. Note that this default |
| 97 | is the reverse of Python's urllib module. |
| 98 | |
| 99 | .. versionadded:: 3.1 |
| 100 | The ``plus`` argument |
| 101 | """ |
| 102 | quote = urllib.parse.quote_plus if plus else urllib.parse.quote |
| 103 | return quote(utf8(value)) |
| 104 | |
| 105 | |
| 106 | @typing.overload |