Package Halberd :: Module clientlib :: Class HTTPClient |
[show private | hide private]
[frames | no frames]

## Class HTTPClient

Known Subclasses:
  `HTTPSClient`

Special-purpose HTTP client.

Method Summary
| ``__init__`(self)` Initializes the object.
| `__del__(self)`
`tuple` | ``getHeaders`(self, address, urlstr)` Talk to the target webserver and fetch MIME headers.
| ``_connect`(self, addr)` Connect to the target address.
`str` | ``_fillTemplate`(self, hostname, port, url, params, query, fragment)` Fills the request template with relevant information.
`tuple` | ``_getHostAndPort`(self, netloc)` Determine the hostname and port to connect to from an URL
`tuple` | ``_getReply`(self)` Read a reply from the server.
| ``_putRequest`(self, address, urlstr)` Sends an HTTP request to the target webserver.
| ``_sendAll`(self, data)` Sends a string to the socket.

Instance Variable Summary
`int` | `bufsize`: Buffer size for network I/O.
`str` | `template`: Template of the HTTP request to be sent to the target.
`float` | `timeout`: Timeout for socket operations (expressed in seconds).
`callable` | `_recv`: Reference to a callable responsible from reading data from the network.

Method Details

### __init__(self) (Constructor) Initializes the object.

### getHeaders(self, address, urlstr) Talk to the target webserver and fetch MIME headers. Parameters: `address` - The target's network address. (type=`tuple`) `urlstr` - URL to use. (type=`str`) Returns: The time when the client started reading the server's response and the MIME headers that were sent. (type=`tuple`)

### _connect(self, addr) Connect to the target address. Parameters: `addr` - The target's address. (type=`tuple`) Raises: `ConnectionRefused` - If it can't reach the target webserver.

### _fillTemplate(self, hostname, port, url, params='', query='', fragment='') Fills the request template with relevant information. Parameters: `hostname` - Target host to reach. (type=`str`) `port` - Remote port. (type=`int`) `url` - URL to use as source. (type=`str`) Returns: A request ready to be sent (type=`str`)

### _getHostAndPort(self, netloc) Determine the hostname and port to connect to from an URL Parameters: `netloc` - Relevant part of the parsed URL. (type=`str`) Returns: Hostname (`str`) and port (`int`) (type=`tuple`)

### _getReply(self) Read a reply from the server. Returns: Time when the data started arriving plus the received data. (type=`tuple`) Raises: `UnknownReply` - If the remote server doesn't return a valid HTTP reply. `TimedOut` - In case reading from the network takes too much time.

### _putRequest(self, address, urlstr) Sends an HTTP request to the target webserver. This method connects to the target server, sends the HTTP request and records a timestamp. Parameters: `address` - Target address. (type=`str`) `urlstr` - A valid Unified Resource Locator. (type=`str`) Raises: `InvalidURL` - In case the URL scheme is not HTTP or HTTPS `ConnectionRefused` - If it can't reach the target webserver. `TimedOut` - If we cannot send the data within the specified time.

### _sendAll(self, data) Sends a string to the socket.

Instance Variable Details

    ### bufsize Buffer size for network I/O. Type: `int` Value:
        1024

    ### template Template of the HTTP request to be sent to the target. Type: `str` Value:
        '''GET %(request)s HTTP/1.1\r
        Host: %(hostname)s%(port)s\r
        Pragma: no-cache\r
        Cache-control: no-cache\r
        User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.7) Gecko/20\
        050414 Firefox/1.0.3\r
        Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, applicati\
        on/x-shockwave-flash, */*\r
        ...

    ### timeout Timeout for socket operations (expressed in seconds). WARNING: changing this value is strongly discouraged. Type: `float` Value:
        2

### _recv Reference to a callable responsible from reading data from the network. Type: `callable`

Generated by Epydoc 2.1 on Thu Aug 24 19:08:31 2006 | http://epydoc.sf.net