urlstd.parse.string_percent_encode#
- urlstd.parse.string_percent_encode(s: str, safe: str, encoding: str = 'utf-8', space_as_plus: bool = False) str #
Returns a percent-encoded string after encoding with encoding.
Invalid surrogates will be replaced with U+FFFD. Also, if the encoding fails, it will be replaced with the appropriate XML character reference.
- Parameters:
s – A string to percent-encode.
safe – ASCII characters that should not be percent-encoded.
encoding – The encoding to encode s.
space_as_plus – If True, replace 0x20 (space) with U+002B (plus sign).
- Returns:
A percent-encoded string after encoding with encoding.
Examples
>>> string_percent_encode('/El Niño/', '/') '/El%20Ni%C3%B1o/'
>>> string_percent_encode('\U0001f308', '') '%F0%9F%8C%88'
>>> string_percent_encode('\ud83c\udf08', '') '%F0%9F%8C%88'
>>> string_percent_encode('\ud83c', '') '%EF%BF%BD' # → '\ufffd'
>>> string_percent_encode('\U0001f308', '', encoding='windows-1252') '%26%23127752%3B' # → '🌈'