Changeset 391 for python/trunk/Doc/library/urllib.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/library/urllib.rst
r2 r391 7 7 .. note:: 8 8 The :mod:`urllib` module has been split into parts and renamed in 9 Python 3 .0to :mod:`urllib.request`, :mod:`urllib.parse`,9 Python 3 to :mod:`urllib.request`, :mod:`urllib.parse`, 10 10 and :mod:`urllib.error`. The :term:`2to3` tool will automatically adapt 11 imports when converting your sources to 3.0.11 imports when converting your sources to Python 3. 12 12 Also note that the :func:`urllib.urlopen` function has been removed in 13 Python 3 .0in favor of :func:`urllib2.urlopen`.13 Python 3 in favor of :func:`urllib2.urlopen`. 14 14 15 15 .. index:: … … 24 24 reading, and no seek operations are available. 25 25 26 .. warning:: When opening HTTPS URLs, it does not attempt to validate the 27 server certificate. Use at your own risk! 28 29 26 30 High-level interface 27 31 -------------------- … … 29 33 .. function:: urlopen(url[, data[, proxies]]) 30 34 31 Open a network object denoted by a URL for reading. If the URL does not have a 32 scheme identifier, or if it has :file:`file:` as its scheme identifier, this 33 opens a local file (without universal newlines); otherwise it opens a socket to 34 a server somewhere on the network. If the connection cannot be made the 35 :exc:`IOError` exception is raised. If all went well, a file-like object is 36 returned. This supports the following methods: :meth:`read`, :meth:`readline`, 37 :meth:`readlines`, :meth:`fileno`, :meth:`close`, :meth:`info`, :meth:`getcode` and 38 :meth:`geturl`. It also has proper support for the :term:`iterator` protocol. One 39 caveat: the :meth:`read` method, if the size argument is omitted or negative, 40 may not read until the end of the data stream; there is no good way to determine 35 Open a network object denoted by a URL for reading. If the URL does not 36 have a scheme identifier, or if it has :file:`file:` as its scheme 37 identifier, this opens a local file (without :term:`universal newlines`); 38 otherwise it opens a socket to a server somewhere on the network. If the 39 connection cannot be made the :exc:`IOError` exception is raised. If all 40 went well, a file-like object is returned. This supports the following 41 methods: :meth:`read`, :meth:`readline`, :meth:`readlines`, :meth:`fileno`, 42 :meth:`close`, :meth:`info`, :meth:`getcode` and :meth:`geturl`. It also 43 has proper support for the :term:`iterator` protocol. One caveat: the 44 :meth:`read` method, if the size argument is omitted or negative, may not 45 read until the end of the data stream; there is no good way to determine 41 46 that the entire stream from a socket has been read in the general case. 42 47 … … 50 55 51 56 The :meth:`info` method returns an instance of the class 52 :class:` httplib.HTTPMessage` containing meta-information associated with the57 :class:`mimetools.Message` containing meta-information associated with the 53 58 URL. When the method is HTTP, these headers are those returned by the server 54 59 at the head of the retrieved HTML page (including Content-Length and … … 128 133 129 134 .. deprecated:: 2.6 130 The :func:`urlopen` function has been removed in Python 3 .0in favor135 The :func:`urlopen` function has been removed in Python 3 in favor 131 136 of :func:`urllib2.urlopen`. 132 137 … … 164 169 165 170 The *Content-Length* is treated as a lower bound: if there's more data to read, 166 urlretrieve reads more data, but if less data is available, it raises the167 exception.171 :func:`urlretrieve` reads more data, but if less data is available, it raises 172 the exception. 168 173 169 174 You can still retrieve the downloaded data in this case, it is stored in the 170 175 :attr:`content` attribute of the exception instance. 171 176 172 If no *Content-Length* header was supplied, urlretrieve can not check the size173 of the data it has downloaded, and just returns it. In this case you just have174 to assume that the download was successful.177 If no *Content-Length* header was supplied, :func:`urlretrieve` can not check 178 the size of the data it has downloaded, and just returns it. In this case you 179 just have to assume that the download was successful. 175 180 176 181 … … 207 212 Replace special characters in *string* using the ``%xx`` escape. Letters, 208 213 digits, and the characters ``'_.-'`` are never quoted. By default, this 209 function is intended for quoting the path section of the URL. The optional214 function is intended for quoting the path section of the URL. The optional 210 215 *safe* parameter specifies additional characters that should not be quoted 211 216 --- its default value is ``'/'``. … … 237 242 .. function:: urlencode(query[, doseq]) 238 243 239 Convert a mapping object or a sequence of two-element tuples to a "url-encoded" 240 string, suitable to pass to :func:`urlopen` above as the optional *data* 241 argument. This is useful to pass a dictionary of form fields to a ``POST`` 242 request. The resulting string is a series of ``key=value`` pairs separated by 243 ``'&'`` characters, where both *key* and *value* are quoted using 244 :func:`quote_plus` above. If the optional parameter *doseq* is present and 245 evaluates to true, individual ``key=value`` pairs are generated for each element 246 of the sequence. When a sequence of two-element tuples is used as the *query* 247 argument, the first element of each tuple is a key and the second is a value. 248 The order of parameters in the encoded string will match the order of parameter 249 tuples in the sequence. The :mod:`urlparse` module provides the functions 244 Convert a mapping object or a sequence of two-element tuples to a 245 "percent-encoded" string, suitable to pass to :func:`urlopen` above as the 246 optional *data* argument. This is useful to pass a dictionary of form 247 fields to a ``POST`` request. The resulting string is a series of 248 ``key=value`` pairs separated by ``'&'`` characters, where both *key* and 249 *value* are quoted using :func:`quote_plus` above. When a sequence of 250 two-element tuples is used as the *query* argument, the first element of 251 each tuple is a key and the second is a value. The value element in itself 252 can be a sequence and in that case, if the optional parameter *doseq* is 253 evaluates to *True*, individual ``key=value`` pairs separated by ``'&'`` are 254 generated for each element of the value sequence for the key. The order of 255 parameters in the encoded string will match the order of parameter tuples in 256 the sequence. The :mod:`urlparse` module provides the functions 250 257 :func:`parse_qs` and :func:`parse_qsl` which are used to parse query strings 251 258 into Python data structures. … … 261 268 .. function:: url2pathname(path) 262 269 263 Convert the path component *path* from an encoded URL to the local syntax for a270 Convert the path component *path* from an percent-encoded URL to the local syntax for a 264 271 path. This does not accept a complete URL. This function uses :func:`unquote` 265 272 to decode *path*. … … 269 276 270 277 This helper function returns a dictionary of scheme to proxy server URL 271 mappings. It scans the environment for variables named ``<scheme>_proxy`` 272 for all operating systems first, and when it cannot find it, looks for proxy 273 information from Mac OSX System Configuration for Mac OS X and Windows 274 Systems Registry for Windows. 278 mappings. It scans the environment for variables named ``<scheme>_proxy``, 279 in case insensitive way, for all operating systems first, and when it cannot 280 find it, looks for proxy information from Mac OSX System Configuration for 281 Mac OS X and Windows Systems Registry for Windows. 282 283 .. note:: 284 urllib also exposes certain utility functions like splittype, splithost and 285 others parsing url into various components. But it is recommended to use 286 :mod:`urlparse` for parsing urls than using these functions directly. 287 Python 3 does not expose these helper functions from :mod:`urllib.parse` 288 module. 275 289 276 290 … … 446 460 code will try to read it, fail with a 550 error, and then perform a directory 447 461 listing for the unreadable file. If fine-grained control is needed, consider 448 using the :mod:`ftplib` module, subclassing :class:`FancyURL Opener`, or changing462 using the :mod:`ftplib` module, subclassing :class:`FancyURLopener`, or changing 449 463 *_urlopener* to meet your needs. 450 464
Note:
See TracChangeset
for help on using the changeset viewer.