Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 :mod:`urllib.parse` --- Parse URLs into components | 1 :mod:`urllib.parse` --- Parse URLs into components |
2 ================================================== | 2 ================================================== |
3 | 3 |
4 .. module:: urllib.parse | 4 .. module:: urllib.parse |
5 :synopsis: Parse URLs into or assemble them from components. | 5 :synopsis: Parse URLs into or assemble them from components. |
6 | 6 |
7 | 7 |
8 .. index:: | 8 .. index:: |
9 single: WWW | 9 single: WWW |
10 single: World Wide Web | 10 single: World Wide Web |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 :func:`urlunsplit`, removing possible *scheme* and *netloc* parts. | 175 :func:`urlunsplit`, removing possible *scheme* and *netloc* parts. |
176 | 176 |
177 | 177 |
178 .. function:: urldefrag(url) | 178 .. function:: urldefrag(url) |
179 | 179 |
180 If *url* contains a fragment identifier, return a modified version of *url* | 180 If *url* contains a fragment identifier, return a modified version of *url* |
181 with no fragment identifier, and the fragment identifier as a separate | 181 with no fragment identifier, and the fragment identifier as a separate |
182 string. If there is no fragment identifier in *url*, return *url* unmodified | 182 string. If there is no fragment identifier in *url*, return *url* unmodified |
183 and an empty string. | 183 and an empty string. |
184 | 184 |
185 .. function:: quote(string[, safe[, encoding[, errors]]]) | 185 .. function:: quote(string[, safe[, encoding[, errors]]]) |
GvR
2008/08/13 17:50:14
Note that the argument is called 's' in the code.
mgiuca
2008/08/14 15:29:00
OK I will change the argument to "string" (in the
GvR
2008/08/18 20:20:32
OK, leave them as positional.
| |
186 | 186 |
187 Replace special characters in *string* using the ``%xx`` escape. Letters, | 187 Replace special characters in *string* using the ``%xx`` escape. Letters, |
188 digits, and the characters ``'_.-'`` are never quoted. The optional *safe* | 188 digits, and the characters ``'_.-'`` are never quoted. The optional *safe* |
189 parameter specifies additional ASCII characters that should not be quoted | 189 parameter specifies additional ASCII characters that should not be quoted |
190 --- its default value is ``'/'``. | 190 --- its default value is ``'/'``. |
191 | 191 |
192 *string* may be either a :class:`str` or a :class:`bytes`. | 192 *string* may be either a :class:`str` or a :class:`bytes`. |
193 | 193 |
194 The optional *encoding* and *errors* parameters specify how to deal with | 194 The optional *encoding* and *errors* parameters specify how to deal with |
195 non-ASCII characters, as accepted by the :meth:`str.encode` method. | 195 non-ASCII characters, as accepted by the :meth:`str.encode` method. |
196 *encoding* defaults to ``'utf-8'``. | 196 *encoding* defaults to ``'utf-8'``. |
197 *errors* defaults to ``'strict'``, meaning unsupported characters raise a | 197 *errors* defaults to ``'strict'``, meaning unsupported characters raise a |
198 :class:`UnicodeEncodeError`. | 198 :class:`UnicodeEncodeError`. |
199 *encoding* and *errors* must not be supplied if *string* is a | 199 *encoding* and *errors* must not be supplied if *string* is a |
200 :class:`bytes`, or a :class:`TypeError` is raised. | 200 :class:`bytes`, or a :class:`TypeError` is raised. |
201 | 201 |
202 Note that ``quote(string, safe, encoding, errors)`` is equivalent to | |
203 ``quote_from_bytes(string.encode(encoding, errors), safe)``. | |
204 | |
202 Example: ``quote('/El Niño/')`` yields ``'/El%20Ni%C3%B1o/'``. | 205 Example: ``quote('/El Niño/')`` yields ``'/El%20Ni%C3%B1o/'``. |
203 | 206 |
204 | 207 |
205 .. function:: quote_plus(string[, safe[, encoding[, errors]]]) | 208 .. function:: quote_plus(string[, safe[, encoding[, errors]]]) |
206 | 209 |
207 Like :func:`quote`, but also replace spaces by plus signs, as required for | 210 Like :func:`quote`, but also replace spaces by plus signs, as required for |
208 quoting HTML form values. Plus signs in the original string are escaped | 211 quoting HTML form values. Plus signs in the original string are escaped |
209 unless they are included in *safe*. It also does not have *safe* default to | 212 unless they are included in *safe*. It also does not have *safe* default to |
210 ``'/'``. | 213 ``'/'``. |
211 | 214 |
212 Example: ``quote_plus('/El Niño/')`` yields ``'%2FEl+Ni%C3%B1o%2F'``. | 215 Example: ``quote_plus('/El Niño/')`` yields ``'%2FEl+Ni%C3%B1o%2F'``. |
213 | 216 |
214 .. function:: quote_from_bytes(bytes[, safe]) | 217 .. function:: quote_from_bytes(bytes[, safe]) |
mgiuca
2008/08/14 15:29:00
Note that here (in the code), I didn't change the
| |
215 | 218 |
216 Like :func:`quote`, but accepts a :class:`bytes` object rather than a | 219 Like :func:`quote`, but accepts a :class:`bytes` object rather than a |
217 :class:`str`, and does not perform string-to-bytes encoding. | 220 :class:`str`, and does not perform string-to-bytes encoding. |
218 | 221 |
219 Example: ``quote_from_bytes(b'/El Ni\xc3\xb1o/')`` yields | 222 Example: ``quote_from_bytes(b'a&\xef')`` yields |
GvR
2008/08/13 17:50:14
I wonder if it wouldn't be better to use a Latin-1
mgiuca
2008/08/14 15:29:00
Do you mean just for the quote_from_bytes example?
GvR
2008/08/18 20:20:32
Perfect.
| |
220 ``'/El%20Ni%C3%B1o/'``. | 223 ``'a%26%EF'``. |
GvR
2008/08/13 17:50:14
Perhaps it's useful to explain that quote(s, enc,
mgiuca
2008/08/14 15:29:00
Yes. (Done).
| |
221 | 224 |
222 .. function:: unquote(string[, encoding[, errors]]) | 225 .. function:: unquote(string[, encoding[, errors]]) |
223 | 226 |
224 Replace ``%xx`` escapes by their single-character equivalent. | 227 Replace ``%xx`` escapes by their single-character equivalent. |
225 The optional *encoding* and *errors* parameters specify how to decode | 228 The optional *encoding* and *errors* parameters specify how to decode |
226 percent-encoded sequences into Unicode characters, as accepted by the | 229 percent-encoded sequences into Unicode characters, as accepted by the |
227 :meth:`bytes.decode` method. | 230 :meth:`bytes.decode` method. |
228 | 231 |
229 *string* must be a :class:`str`. | 232 *string* must be a :class:`str`. |
230 | 233 |
231 *encoding* defaults to ``'utf-8'``. | 234 *encoding* defaults to ``'utf-8'``. |
232 *errors* defaults to ``'strict'``, meaning invalid sequences raise | 235 *errors* defaults to ``'replace'``, meaning invalid sequences are replaced |
233 a :class:`UnicodeDecodeError`. | 236 by a placeholder character. |
234 | 237 |
235 Example: ``unquote('/El%20Ni%C3%B1o/')`` yields ``'/El Niño/'``. | 238 Example: ``unquote('/El%20Ni%C3%B1o/')`` yields ``'/El Niño/'``. |
236 | 239 |
237 | 240 |
238 .. function:: unquote_plus(string[, encoding[, errors]]) | 241 .. function:: unquote_plus(string[, encoding[, errors]]) |
239 | 242 |
240 Like :func:`unquote`, but also replace plus signs by spaces, as required for | 243 Like :func:`unquote`, but also replace plus signs by spaces, as required for |
241 unquoting HTML form values. | 244 unquoting HTML form values. |
242 | 245 |
243 *string* must be a :class:`str`. | 246 *string* must be a :class:`str`. |
244 | 247 |
245 Example: ``unquote_plus('/El+Ni%C3%B1o/')`` yields ``'/El Niño/'``. | 248 Example: ``unquote_plus('/El+Ni%C3%B1o/')`` yields ``'/El Niño/'``. |
246 | 249 |
247 .. function:: unquote_to_bytes(string) | 250 .. function:: unquote_to_bytes(string) |
248 | 251 |
249 Replace ``%xx`` escapes by their single-octet equivalent, and return a | 252 Replace ``%xx`` escapes by their single-octet equivalent, and return a |
250 :class:`bytes` object. | 253 :class:`bytes` object. |
251 | 254 |
252 *string* must be a :class:`str`. | 255 *string* may be either a :class:`str` or a :class:`bytes`. |
253 | 256 |
254 Unescaped non-ASCII characters in the input string are encoded into UTF-8 | 257 If it is a :class:`str`, unescaped non-ASCII characters in *string* |
255 bytes. | 258 are encoded into UTF-8 bytes. |
256 | 259 |
257 Example: ``unquote_to_bytes('/El%20Ni%C3%B1o/')`` yields | 260 Example: ``unquote_to_bytes('a%26%EF')`` yields |
258 ``b'/El Ni\xc3\xb1o/'``. | 261 ``b'a&\xef'``. |
259 | 262 |
260 | 263 |
261 .. function:: urlencode(query[, doseq]) | 264 .. function:: urlencode(query[, doseq]) |
262 | 265 |
263 Convert a mapping object or a sequence of two-element tuples to a "url-encod ed" | 266 Convert a mapping object or a sequence of two-element tuples to a "url-encod ed" |
264 string, suitable to pass to :func:`urlopen` above as the optional *data* | 267 string, suitable to pass to :func:`urlopen` above as the optional *data* |
265 argument. This is useful to pass a dictionary of form fields to a ``POST`` | 268 argument. This is useful to pass a dictionary of form fields to a ``POST`` |
266 request. The resulting string is a series of ``key=value`` pairs separated b y | 269 request. The resulting string is a series of ``key=value`` pairs separated b y |
267 ``'&'`` characters, where both *key* and *value* are quoted using | 270 ``'&'`` characters, where both *key* and *value* are quoted using |
268 :func:`quote_plus` above. If the optional parameter *doseq* is present and | 271 :func:`quote_plus` above. If the optional parameter *doseq* is present and |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 | 338 |
336 Concrete class for :func:`urlparse` results. The :meth:`__new__` method is | 339 Concrete class for :func:`urlparse` results. The :meth:`__new__` method is |
337 overridden to support checking that the right number of arguments are passed. | 340 overridden to support checking that the right number of arguments are passed. |
338 | 341 |
339 | 342 |
340 .. class:: SplitResult(scheme, netloc, path, query, fragment) | 343 .. class:: SplitResult(scheme, netloc, path, query, fragment) |
341 | 344 |
342 Concrete class for :func:`urlsplit` results. The :meth:`__new__` method is | 345 Concrete class for :func:`urlsplit` results. The :meth:`__new__` method is |
343 overridden to support checking that the right number of arguments are passed. | 346 overridden to support checking that the right number of arguments are passed. |
344 | 347 |
LEFT | RIGHT |