httplib
index
/usr/lib/python2.1/httplib.py

HTTP/1.1 client library
 
<intro stuff goes here>
<other stuff, too>
 
HTTPConnection go through a number of "states", which defines when a client
may legally make another request or fetch the response for a particular
request. This diagram details these state transitions:
 
    (null)
      |
      | HTTPConnection()
      v
    Idle
      |
      | putrequest()
      v
    Request-started
      |
      | ( putheader() )*  endheaders()
      v
    Request-sent
      |
      | response = getresponse()
      v
    Unread-response   [Response-headers-read]
      |\____________________
      |                     |
      | response.read()     | putrequest()
      v                     v
    Idle                  Req-started-unread-response
                     ______/|
                   /        |
   response.read() |        | ( putheader() )*  endheaders()
                   v        v
       Request-started    Req-sent-unread-response
                            |
                            | response.read()
                            v
                          Request-sent
 
This diagram presents the following rules:
  -- a second request may not be started until {response-headers-read}
  -- a response [object] cannot be retrieved until {request-sent}
  -- there is no differentiation between an unread response body and a
     partially read response body
 
Note: this enforcement is applied by the HTTPConnection class. The
      HTTPResponse class does not enforce this state machine, which
      implies sophisticated clients may accelerate the request/response
      pipeline. Caution should be taken, though: accelerating the states
      beyond the above pattern may imply knowledge of the server's
      connection-close behavior for certain requests. For example, it
      is impossible to tell whether the server will close the connection
      UNTIL the response headers have been read; this means that further
      requests cannot be placed into the pipeline until it is known that
      the server will NOT be closing the connection.
 
Logical State                  __state            __response
-------------                  -------            ----------
Idle                           _CS_IDLE           None
Request-started                _CS_REQ_STARTED    None
Request-sent                   _CS_REQ_SENT       None
Unread-response                _CS_IDLE           <response_class>
Req-started-unread-response    _CS_REQ_STARTED    <response_class>
Req-sent-unread-response       _CS_REQ_SENT       <response_class>

 
Modules
            
mimetools
socket

 
Classes
            
exceptions.Exception
HTTPException
BadStatusLine
IllegalKeywordArgument
ImproperConnectionState
CannotSendHeader
CannotSendRequest
ResponseNotReady
IncompleteRead
NotConnected
UnimplementedFileMode
UnknownProtocol
UnknownTransferEncoding
HTTPException
BadStatusLine
IllegalKeywordArgument
ImproperConnectionState
CannotSendHeader
CannotSendRequest
ResponseNotReady
IncompleteRead
NotConnected
UnimplementedFileMode
UnknownProtocol
UnknownTransferEncoding
FakeSocket
HTTP
HTTPS
HTTPConnection
HTTPSConnection
HTTPResponse

 
class BadStatusLine(HTTPException)
       
  
__getitem__(...) from exceptions.Exception
__init__(self, line)
__str__(...) from exceptions.Exception

 
class CannotSendHeader(ImproperConnectionState)
       
  
__getitem__(...) from exceptions.Exception
__init__(...) from exceptions.Exception
__str__(...) from exceptions.Exception

 
class CannotSendRequest(ImproperConnectionState)
       
  
__getitem__(...) from exceptions.Exception
__init__(...) from exceptions.Exception
__str__(...) from exceptions.Exception

 
class FakeSocket
       
  
__getattr__(self, attr)
__init__(self, sock, ssl)
makefile(self, mode, bufsize=None)
Return a readable file-like object with data from socket.
 
This method offers only partial support for the makefile
interface of a real socket.  It only supports modes 'r' and
'rb' and the bufsize argument is ignored.
 
The returned object contains *all* of the file data
recv(self, len=1024, flags=0)
send(self, stuff, flags=0)

 
class HTTP
      Compatibility class with httplib.py from 1.5.
 
  
__init__(self, host='', port=None, **x509)
Provide a default host, since the superclass requires one.
close(self)
connect(self, host=None, port=None)
Accept arguments to set the host/port, since the superclass doesn't.
getfile(self)
Provide a getfile, since the superclass' does not use this concept.
getreply(self)
Compat definition since superclass does not define it.
 
Returns a tuple consisting of:
- server status code (e.g. '200' if all goes well)
- server "reason" corresponding to status code
- any RFC822 headers in the response from the server
putheader(self, header, *values)
The superclass allows only one value argument.
set_debuglevel(self, debuglevel)

 
class HTTPConnection
       
  
__init__(self, host, port=None)
_send_request(self, method, url, body, headers)
_set_hostport(self, host, port)
close(self)
Close the connection to the HTTP server.
connect(self)
Connect to the host and port specified in __init__.
endheaders(self)
Indicate that the last header line has been sent to the server.
getresponse(self)
Get the response from the server.
putheader(self, header, value)
Send a request header line to the server.
 
For example: h.putheader('Accept', 'text/html')
putrequest(self, method, url)
Send a request to the server.
 
`method' specifies an HTTP request method, e.g. 'GET'.
`url' specifies the object being requested, e.g. '/index.html'.
request(self, method, url, body=None, headers={})
Send a complete request to the server.
send(self, str)
Send `str' to the server.
set_debuglevel(self, level)

 
class HTTPException(exceptions.Exception)
       
  
__getitem__(...) from exceptions.Exception
__init__(...) from exceptions.Exception
__str__(...) from exceptions.Exception

 
class HTTPResponse
       
  
__init__(self, sock, debuglevel=0)
_safe_read(self, amt)
Read the number of bytes requested, compensating for partial reads.
 
Normally, we have a blocking socket, but a read() can be interrupted
by a signal (resulting in a partial read).
 
Note that we cannot distinguish between EOF and an interrupt when zero
bytes have been read. IncompleteRead() will be raised in this
situation.
 
This function should be used when <amt> bytes "should" be present for
reading. If the bytes are truly not available (due to EOF), then the
IncompleteRead exception can be used to detect the problem.
begin(self)
close(self)
getheader(self, name, default=None)
isclosed(self)
read(self, amt=None)

 
class HTTPS(HTTP)
      Compatibility with 1.5 httplib interface
 
Python 1.5.2 did not have an HTTPS class, but it defined an
interface for sending http requests that is also useful for
https.
 
  
__init__(self, host='', port=None, **x509) from HTTP
close(self) from HTTP
connect(self, host=None, port=None) from HTTP
getfile(self) from HTTP
getreply(self) from HTTP
putheader(self, header, *values) from HTTP
set_debuglevel(self, debuglevel) from HTTP

 
class HTTPSConnection(HTTPConnection)
      This class allows communication via SSL.
 
  
__init__(self, host, port=None, **x509)
_send_request(self, method, url, body, headers) from HTTPConnection
_set_hostport(self, host, port) from HTTPConnection
close(self) from HTTPConnection
connect(self)
Connect to a host on a given (SSL) port.
endheaders(self) from HTTPConnection
getresponse(self) from HTTPConnection
putheader(self, header, value) from HTTPConnection
putrequest(self, method, url) from HTTPConnection
request(self, method, url, body=None, headers={}) from HTTPConnection
send(self, str) from HTTPConnection
set_debuglevel(self, level) from HTTPConnection

 
class IllegalKeywordArgument(HTTPException)
       
  
__getitem__(...) from exceptions.Exception
__init__(...) from exceptions.Exception
__str__(...) from exceptions.Exception

 
class ImproperConnectionState(HTTPException)
       
  
__getitem__(...) from exceptions.Exception
__init__(...) from exceptions.Exception
__str__(...) from exceptions.Exception

 
class IncompleteRead(HTTPException)
       
  
__getitem__(...) from exceptions.Exception
__init__(self, partial)
__str__(...) from exceptions.Exception

 
class NotConnected(HTTPException)
       
  
__getitem__(...) from exceptions.Exception
__init__(...) from exceptions.Exception
__str__(...) from exceptions.Exception

 
class ResponseNotReady(ImproperConnectionState)
       
  
__getitem__(...) from exceptions.Exception
__init__(...) from exceptions.Exception
__str__(...) from exceptions.Exception

 
class UnimplementedFileMode(HTTPException)
       
  
__getitem__(...) from exceptions.Exception
__init__(...) from exceptions.Exception
__str__(...) from exceptions.Exception

 
class UnknownProtocol(HTTPException)
       
  
__getitem__(...) from exceptions.Exception
__init__(self, version)
__str__(...) from exceptions.Exception

 
class UnknownTransferEncoding(HTTPException)
       
  
__getitem__(...) from exceptions.Exception
__init__(...) from exceptions.Exception
__str__(...) from exceptions.Exception

 
error = class HTTPException(exceptions.Exception)
       
  
__getitem__(...) from exceptions.Exception
__init__(...) from exceptions.Exception
__str__(...) from exceptions.Exception

 
Functions
            
StringIO(...)
StringIO([s]) -- Return a StringIO-like stream for reading or writing
test()
Test this module.
 
The test consists of retrieving and displaying the Python
home page, along with the error code and error string returned
by the www.python.org server.

 
Data
             HTTPS_PORT = 443
HTTP_PORT = 80
_CS_IDLE = 'Idle'
_CS_REQ_SENT = 'Request-sent'
_CS_REQ_STARTED = 'Request-started'
_UNKNOWN = 'UNKNOWN'
__all__ = ['HTTP']
__file__ = '/usr/lib/python2.1/httplib.pyc'
__name__ = 'httplib'