@@ -182,36 +182,84 @@ The :mod:`urllib.parse` module defines the following functions:
182182 string. If there is no fragment identifier in *url *, return *url * unmodified
183183 and an empty string.
184184
185- .. function :: quote(string[, safe])
185+ .. function :: quote(string[, safe[, encoding[, errors]] ])
186186
187187 Replace special characters in *string * using the ``%xx `` escape. Letters,
188188 digits, and the characters ``'_.-' `` are never quoted. The optional *safe *
189- parameter specifies additional characters that should not be quoted --- its
190- default value is ``'/' ``.
189+ parameter specifies additional ASCII characters that should not be quoted
190+ --- its default value is ``'/' ``.
191191
192- Example: `` quote('/~connolly/') `` yields `` '/%7econnolly/' ` `.
192+ * string * may be either a :class: ` str ` or a :class: ` bytes `.
193193
194+ The optional *encoding * and *errors * parameters specify how to deal with
195+ non-ASCII characters, as accepted by the :meth: `str.encode ` method.
196+ *encoding * defaults to ``'utf-8' ``.
197+ *errors * defaults to ``'strict' ``, meaning unsupported characters raise a
198+ :class: `UnicodeEncodeError `.
199+ *encoding * and *errors * must not be supplied if *string * is a
200+ :class: `bytes `, or a :class: `TypeError ` is raised.
194201
195- .. function :: quote_plus(string[, safe])
202+ Note that ``quote(string, safe, encoding, errors) `` is equivalent to
203+ ``quote_from_bytes(string.encode(encoding, errors), safe) ``.
204+
205+ Example: ``quote('/El Niño/') `` yields ``'/El%20Ni%C3%B1o/' ``.
206+
207+
208+ .. function :: quote_plus(string[, safe[, encoding[, errors]]])
196209
197210 Like :func: `quote `, but also replace spaces by plus signs, as required for
198211 quoting HTML form values. Plus signs in the original string are escaped
199212 unless they are included in *safe *. It also does not have *safe * default to
200213 ``'/' ``.
201214
215+ Example: ``quote_plus('/El Niño/') `` yields ``'%2FEl+Ni%C3%B1o%2F' ``.
216+
217+ .. function :: quote_from_bytes(bytes[, safe])
202218
203- .. function :: unquote(string)
219+ Like :func: `quote `, but accepts a :class: `bytes ` object rather than a
220+ :class: `str `, and does not perform string-to-bytes encoding.
221+
222+ Example: ``quote_from_bytes(b'a&\xef') `` yields
223+ ``'a%26%EF' ``.
224+
225+ .. function :: unquote(string[, encoding[, errors]])
204226
205227 Replace ``%xx `` escapes by their single-character equivalent.
228+ The optional *encoding * and *errors * parameters specify how to decode
229+ percent-encoded sequences into Unicode characters, as accepted by the
230+ :meth: `bytes.decode ` method.
231+
232+ *string * must be a :class: `str `.
233+
234+ *encoding * defaults to ``'utf-8' ``.
235+ *errors * defaults to ``'replace' ``, meaning invalid sequences are replaced
236+ by a placeholder character.
206237
207- Example: ``unquote('/%7Econnolly /') `` yields ``'/~connolly /' ``.
238+ Example: ``unquote('/El%20Ni%C3%B1o /') `` yields ``'/El Niño /' ``.
208239
209240
210- .. function :: unquote_plus(string)
241+ .. function :: unquote_plus(string[, encoding[, errors]] )
211242
212243 Like :func: `unquote `, but also replace plus signs by spaces, as required for
213244 unquoting HTML form values.
214245
246+ *string * must be a :class: `str `.
247+
248+ Example: ``unquote_plus('/El+Ni%C3%B1o/') `` yields ``'/El Niño/' ``.
249+
250+ .. function :: unquote_to_bytes(string)
251+
252+ Replace ``%xx `` escapes by their single-octet equivalent, and return a
253+ :class: `bytes ` object.
254+
255+ *string * may be either a :class: `str ` or a :class: `bytes `.
256+
257+ If it is a :class: `str `, unescaped non-ASCII characters in *string *
258+ are encoded into UTF-8 bytes.
259+
260+ Example: ``unquote_to_bytes('a%26%EF') `` yields
261+ ``b'a&\xef' ``.
262+
215263
216264.. function :: urlencode(query[, doseq])
217265
0 commit comments