Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Doc/library/urllib.rst

    r2 r391  
    77.. note::
    88    The :mod:`urllib` module has been split into parts and renamed in
    9     Python 3.0 to :mod:`urllib.request`, :mod:`urllib.parse`,
     9    Python 3 to :mod:`urllib.request`, :mod:`urllib.parse`,
    1010    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.
    1212    Also note that the :func:`urllib.urlopen` function has been removed in
    13     Python 3.0 in favor of :func:`urllib2.urlopen`.
     13    Python 3 in favor of :func:`urllib2.urlopen`.
    1414
    1515.. index::
     
    2424reading, and no seek operations are available.
    2525
     26.. warning:: When opening HTTPS URLs, it does not attempt to validate the
     27   server certificate.  Use at your own risk!
     28
     29
    2630High-level interface
    2731--------------------
     
    2933.. function:: urlopen(url[, data[, proxies]])
    3034
    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
    4146   that the entire stream from a socket has been read in the general case.
    4247
     
    5055
    5156   The :meth:`info` method returns an instance of the class
    52    :class:`httplib.HTTPMessage` containing meta-information associated with the
     57   :class:`mimetools.Message` containing meta-information associated with the
    5358   URL.  When the method is HTTP, these headers are those returned by the server
    5459   at the head of the retrieved HTML page (including Content-Length and
     
    128133
    129134   .. deprecated:: 2.6
    130       The :func:`urlopen` function has been removed in Python 3.0 in favor
     135      The :func:`urlopen` function has been removed in Python 3 in favor
    131136      of :func:`urllib2.urlopen`.
    132137
     
    164169
    165170      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 the
    167       exception.
     171      :func:`urlretrieve` reads more data, but if less data is available,  it raises
     172      the exception.
    168173
    169174      You can still retrieve the downloaded data in this case, it is stored  in the
    170175      :attr:`content` attribute of the exception instance.
    171176
    172       If no *Content-Length* header was supplied, urlretrieve can not check the size
    173       of the data it has downloaded, and just returns it.  In this case you just have
    174       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.
    175180
    176181
     
    207212   Replace special characters in *string* using the ``%xx`` escape. Letters,
    208213   digits, and the characters ``'_.-'`` are never quoted. By default, this
    209    function is intended for quoting the path section of the URL.The optional
     214   function is intended for quoting the path section of the URL. The optional
    210215   *safe* parameter specifies additional characters that should not be quoted
    211216   --- its default value is ``'/'``.
     
    237242.. function:: urlencode(query[, doseq])
    238243
    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
    250257   :func:`parse_qs` and :func:`parse_qsl` which are used to parse query strings
    251258   into Python data structures.
     
    261268.. function:: url2pathname(path)
    262269
    263    Convert the path component *path* from an encoded URL to the local syntax for a
     270   Convert the path component *path* from an percent-encoded URL to the local syntax for a
    264271   path.  This does not accept a complete URL.  This function uses :func:`unquote`
    265272   to decode *path*.
     
    269276
    270277   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.
    275289
    276290
     
    446460  code will try to read it, fail with a 550 error, and then perform a directory
    447461  listing for the unreadable file. If fine-grained control is needed, consider
    448   using the :mod:`ftplib` module, subclassing :class:`FancyURLOpener`, or changing
     462  using the :mod:`ftplib` module, subclassing :class:`FancyURLopener`, or changing
    449463  *_urlopener* to meet your needs.
    450464
Note: See TracChangeset for help on using the changeset viewer.