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/httplib.rst

    r2 r391  
    77.. note::
    88   The :mod:`httplib` module has been renamed to :mod:`http.client` in Python
    9    3.0.  The :term:`2to3` tool will automatically adapt imports when converting
    10    your sources to 3.0.
     9   3.  The :term:`2to3` tool will automatically adapt imports when converting
     10   your sources to Python 3.
    1111
    1212
     
    1717.. index:: module: urllib
    1818
     19**Source code:** :source:`Lib/httplib.py`
     20
     21--------------
     22
    1923This module defines classes which implement the client side of the HTTP and
    2024HTTPS protocols.  It is normally not used directly --- the module :mod:`urllib`
     
    3539
    3640
    37 .. class:: HTTPConnection(host[, port[, strict[, timeout]]])
     41.. class:: HTTPConnection(host[, port[, strict[, timeout[, source_address]]]])
    3842
    3943   An :class:`HTTPConnection` instance represents one transaction with an HTTP
     
    4751   operations (like connection attempts) will timeout after that many seconds
    4852   (if it is not given, the global default timeout setting is used).
     53   The optional *source_address* parameter may be a tuple of a (host, port)
     54   to use as the source address the HTTP connection is made from.
    4955
    5056   For example, the following calls all create instances that connect to the server
     
    6167      *timeout* was added.
    6268
    63 
    64 .. class:: HTTPSConnection(host[, port[, key_file[, cert_file[, strict[, timeout]]]]])
     69   .. versionchanged:: 2.7
     70      *source_address* was added.
     71
     72
     73.. class:: HTTPSConnection(host[, port[, key_file[, cert_file[, strict[, timeout[, source_address]]]]]])
    6574
    6675   A subclass of :class:`HTTPConnection` that uses SSL for communication with
     
    6978   certificate chain file.
    7079
    71    .. note::
    72 
    73       This does not do any certificate verification.
     80   .. warning::
     81      This does not do any verification of the server's certificate.
    7482
    7583   .. versionadded:: 2.0
     
    7886      *timeout* was added.
    7987
    80 
    81 .. class:: HTTPResponse(sock[, debuglevel=0][, strict=0])
     88   .. versionchanged:: 2.7
     89      *source_address* was added.
     90
     91
     92.. class:: HTTPResponse(sock, debuglevel=0, strict=0)
    8293
    8394   Class whose instances are returned upon successful connection.  Not instantiated
     
    8596
    8697   .. versionadded:: 2.0
     98
     99.. class:: HTTPMessage
     100
     101   An :class:`HTTPMessage` instance is used to hold the headers from an HTTP
     102   response. It is implemented using the :class:`mimetools.Message` class and
     103   provides utility functions to deal with HTTP Headers. It is not directly
     104   instantiated by the users.
     105
    87106
    88107The following exceptions are raised as appropriate:
     
    429448
    430449
     450.. method:: HTTPConnection.set_tunnel(host,port=None, headers=None)
     451
     452   Set the host and the port for HTTP Connect Tunnelling. Normally used when
     453   it is required to do HTTPS Conection through a proxy server.
     454
     455   The headers argument should be a mapping of extra HTTP headers to send
     456   with the CONNECT request.
     457
     458   .. versionadded:: 2.7
     459
     460
    431461.. method:: HTTPConnection.connect()
    432462
     
    463493
    464494
    465 .. method:: HTTPConnection.endheaders()
    466 
    467    Send a blank line to the server, signalling the end of the headers.
     495.. method:: HTTPConnection.endheaders(message_body=None)
     496
     497   Send a blank line to the server, signalling the end of the headers. The
     498   optional *message_body* argument can be used to pass a message body
     499   associated with the request.  The message body will be sent in the same
     500   packet as the message headers if it is string, otherwise it is sent in a
     501   separate packet.
     502
     503   .. versionchanged:: 2.7
     504      *message_body* was added.
    468505
    469506
     
    500537   .. versionadded:: 2.4
    501538
     539.. method:: HTTPResponse.fileno()
     540
     541   Returns the ``fileno`` of the underlying socket.
    502542
    503543.. attribute:: HTTPResponse.msg
     
    542582   >>> conn.close()
    543583
     584Here is an example session that uses the ``HEAD`` method.  Note that the
     585``HEAD`` method never returns any data. ::
     586
     587   >>> import httplib
     588   >>> conn = httplib.HTTPConnection("www.python.org")
     589   >>> conn.request("HEAD","/index.html")
     590   >>> res = conn.getresponse()
     591   >>> print res.status, res.reason
     592   200 OK
     593   >>> data = res.read()
     594   >>> print len(data)
     595   0
     596   >>> data == ''
     597   True
     598
    544599Here is an example session that shows how to ``POST`` requests::
    545600
    546601   >>> import httplib, urllib
    547    >>> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
     602   >>> params = urllib.urlencode({'@number': 12524, '@type': 'issue', '@action': 'show'})
    548603   >>> headers = {"Content-type": "application/x-www-form-urlencoded",
    549604   ...            "Accept": "text/plain"}
    550    >>> conn = httplib.HTTPConnection("musi-cal.mojam.com:80")
    551    >>> conn.request("POST", "/cgi-bin/query", params, headers)
     605   >>> conn = httplib.HTTPConnection("bugs.python.org")
     606   >>> conn.request("POST", "", params, headers)
    552607   >>> response = conn.getresponse()
    553608   >>> print response.status, response.reason
    554    200 OK
     609   302 Found
    555610   >>> data = response.read()
     611   >>> data
     612   'Redirecting to <a href="http://bugs.python.org/issue12524">http://bugs.python.org/issue12524</a>'
    556613   >>> conn.close()
    557614
     615Client side ``HTTP PUT`` requests are very similar to ``POST`` requests. The
     616difference lies only the server side where HTTP server will allow resources to
     617be created via ``PUT`` request. Here is an example session that shows how to do
     618``PUT`` request using httplib::
     619
     620    >>> # This creates an HTTP message
     621    >>> # with the content of BODY as the enclosed representation
     622    >>> # for the resource http://localhost:8080/foobar
     623    ...
     624    >>> import httplib
     625    >>> BODY = "***filecontents***"
     626    >>> conn = httplib.HTTPConnection("localhost", 8080)
     627    >>> conn.request("PUT", "/file", BODY)
     628    >>> response = conn.getresponse()
     629    >>> print response.status, response.reason
     630    200, OK
     631
Note: See TracChangeset for help on using the changeset viewer.