httplib
index
/usr/lib/python2.2/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
            
errno
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)
       
  
Method resolution order:
BadStatusLine
HTTPException
exceptions.Exception

Methods defined here:
__init__(self, line)

Data and non-method functions defined here:
__doc__ = None
__module__ = 'httplib'

Methods inherited from exceptions.Exception:
__getitem__(...)
__str__(...)
 
class CannotSendHeader(ImproperConnectionState)
       
  
Method resolution order:
CannotSendHeader
ImproperConnectionState
HTTPException
exceptions.Exception

Data and non-method functions defined here:
__doc__ = None
__module__ = 'httplib'

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)
 
class CannotSendRequest(ImproperConnectionState)
       
  
Method resolution order:
CannotSendRequest
ImproperConnectionState
HTTPException
exceptions.Exception

Data and non-method functions defined here:
__doc__ = None
__module__ = 'httplib'

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)
 
class FakeSocket
       
   Methods defined here:
__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)

Data and non-method functions defined here:
__doc__ = None
__module__ = 'httplib'
 
class HTTP
      Compatibility class with httplib.py from 1.5.
 
   Methods defined here:
__init__(self, host='', port=None)
Provide a default host, since the superclass requires one.
_setup(self, conn)
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.

Data and non-method functions defined here:
__doc__ = 'Compatibility class with httplib.py from 1.5.'
__module__ = 'httplib'
_connection_class = <class httplib.HTTPConnection>
_http_vsn = 10
_http_vsn_str = 'HTTP/1.0'
debuglevel = 0
 
class HTTPConnection
       
   Methods defined here:
__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)

Data and non-method functions defined here:
__doc__ = None
__module__ = 'httplib'
_http_vsn = 11
_http_vsn_str = 'HTTP/1.1'
auto_open = 1
debuglevel = 0
default_port = 80
response_class = <class httplib.HTTPResponse>
 
class HTTPException(exceptions.Exception)
       
   Data and non-method functions defined here:
__doc__ = None
__module__ = 'httplib'

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)
 
class HTTPResponse
       
   Methods defined here:
__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)

Data and non-method functions defined here:
__doc__ = None
__module__ = 'httplib'
 
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.
 
   Methods defined here:
__init__(self, host='', port=None, **x509)

Data and non-method functions defined here:
__doc__ = 'Compatibility with 1.5 httplib interface\n\n ...hat is also useful for\n https.\n '
__module__ = 'httplib'
_connection_class = <class httplib.HTTPSConnection>
This class allows communication via SSL.

Methods inherited from HTTP:
_setup(self, conn)
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.

Data and non-method functions inherited from HTTP:
_http_vsn = 10
_http_vsn_str = 'HTTP/1.0'
debuglevel = 0
 
class HTTPSConnection(HTTPConnection)
      This class allows communication via SSL.
 
   Methods defined here:
__init__(self, host, port=None, **x509)
connect(self)
Connect to a host on a given (SSL) port.

Data and non-method functions defined here:
__doc__ = 'This class allows communication via SSL.'
__module__ = 'httplib'
default_port = 443

Methods inherited from HTTPConnection:
_send_request(self, method, url, body, headers)
_set_hostport(self, host, port)
close(self)
Close the connection to the HTTP server.
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)

Data and non-method functions inherited from HTTPConnection:
_http_vsn = 11
_http_vsn_str = 'HTTP/1.1'
auto_open = 1
debuglevel = 0
response_class = <class httplib.HTTPResponse>
 
class IllegalKeywordArgument(HTTPException)
       
  
Method resolution order:
IllegalKeywordArgument
HTTPException
exceptions.Exception

Data and non-method functions defined here:
__doc__ = None
__module__ = 'httplib'

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)
 
class ImproperConnectionState(HTTPException)
       
  
Method resolution order:
ImproperConnectionState
HTTPException
exceptions.Exception

Data and non-method functions defined here:
__doc__ = None
__module__ = 'httplib'

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)
 
class IncompleteRead(HTTPException)
       
  
Method resolution order:
IncompleteRead
HTTPException
exceptions.Exception

Methods defined here:
__init__(self, partial)

Data and non-method functions defined here:
__doc__ = None
__module__ = 'httplib'

Methods inherited from exceptions.Exception:
__getitem__(...)
__str__(...)
 
class NotConnected(HTTPException)
       
  
Method resolution order:
NotConnected
HTTPException
exceptions.Exception

Data and non-method functions defined here:
__doc__ = None
__module__ = 'httplib'

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)
 
class ResponseNotReady(ImproperConnectionState)
       
  
Method resolution order:
ResponseNotReady
ImproperConnectionState
HTTPException
exceptions.Exception

Data and non-method functions defined here:
__doc__ = None
__module__ = 'httplib'

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)
 
class UnimplementedFileMode(HTTPException)
       
  
Method resolution order:
UnimplementedFileMode
HTTPException
exceptions.Exception

Data and non-method functions defined here:
__doc__ = None
__module__ = 'httplib'

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)
 
class UnknownProtocol(HTTPException)
       
  
Method resolution order:
UnknownProtocol
HTTPException
exceptions.Exception

Methods defined here:
__init__(self, version)

Data and non-method functions defined here:
__doc__ = None
__module__ = 'httplib'

Methods inherited from exceptions.Exception:
__getitem__(...)
__str__(...)
 
class UnknownTransferEncoding(HTTPException)
       
  
Method resolution order:
UnknownTransferEncoding
HTTPException
exceptions.Exception

Data and non-method functions defined here:
__doc__ = None
__module__ = 'httplib'

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)
 
error = class HTTPException(exceptions.Exception)
       
   Data and non-method functions defined here:
__doc__ = None
__module__ = 'httplib'

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)
 
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', 'HTTPResponse', 'HTTPConnection', 'HTTPSConnection', 'HTTPException', 'NotConnected', 'UnknownProtocol', 'UnknownTransferEncoding', 'IllegalKeywordArgument', 'UnimplementedFileMode', 'IncompleteRead', 'ImproperConnectionState', 'CannotSendRequest', 'CannotSendHeader', 'ResponseNotReady', 'BadStatusLine', 'error']
__file__ = '/usr/lib/python2.2/httplib.pyc'
__name__ = 'httplib'