Package restkit :: Module client :: Class Client
[hide private]

Class Client

source code

object --+
         |
        Client

A client handle a connection at a time. A client is threadsafe,
    but an handled shouldn't be shared between threads. All connections
    are shared between threads via a pool.

    >>> from restkit import *
    >>> c = Client()
    >>> r = c.request("http://google.com")
    r>>> r.status
    '301 Moved Permanently'
    >>> r.body_string()
    '<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
'
    >>> c.follow_redirect = True
    >>> r = c.request("http://google.com")
    >>> r.status
    '200 OK'

    

Nested Classes [hide private]
  response_class
Instance Methods [hide private]
 
__init__(self, follow_redirect=False, force_follow_redirect=False, max_follow_redirect=5, filters=None, decompress=True, max_status_line_garbage=None, max_header_count=0, pool=None, response_class=None, timeout=None, use_proxy=False, max_tries=3, wait_tries=0.3, pool_size=10, backend='thread', **ssl_args)
Client parameters ~~~~~~~~~~~~~~~~~
source code
 
load_filters(self)
Populate filters from self.filters.
source code
 
get_connection(self, request)
get a connection from the pool or create new one.
source code
 
proxy_connection(self, request, req_addr, is_ssl)
do the proxy connection
source code
 
make_headers_string(self, request, extra_headers=None)
create final header string
source code
 
perform(self, request)
perform the request.
source code
 
request(self, url, method='GET', body=None, headers=None)
perform immediatly a new request
source code
 
redirect(self, location, request)
reset request, set new url of request and perform it
source code
 
get_response(self, request, connection)
return final respons, it is only accessible via peform method
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  version = (1, 1)
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, follow_redirect=False, force_follow_redirect=False, max_follow_redirect=5, filters=None, decompress=True, max_status_line_garbage=None, max_header_count=0, pool=None, response_class=None, timeout=None, use_proxy=False, max_tries=3, wait_tries=0.3, pool_size=10, backend='thread', **ssl_args)
(Constructor)

source code 

Client parameters
~~~~~~~~~~~~~~~~~

:param follow_redirect: follow redirection, by default False
:param max_ollow_redirect: number of redirections available
:filters: http filters to pass
:param decompress: allows the client to decompress the response
body
:param max_status_line_garbage: defines the maximum number of ignorable
lines before we expect a HTTP response's status line. With
HTTP/1.1 persistent connections, the problem arises that broken
scripts could return a wrong Content-Length (there are more
bytes sent than specified).  Unfortunately, in some cases, this
cannot be detected after the bad response, but only before the
next one. So the client is abble to skip bad lines using this
limit. 0 disable garbage collection, None means unlimited number
of tries.
:param max_header_count:  determines the maximum HTTP header count
allowed. by default no limit.
:param pool: the pool to use inherited from socketpool.Pool. By
default we use the global one.
:param response_class: the response class to use
:param timeout: the default timeout of the connection
(SO_TIMEOUT)

:param max_tries: the number of tries before we give up a
connection
:param wait_tries: number of time we wait between each tries.
:attr pool_size: int, default 10. Maximum number of connections we
keep in the default pool.
:param ssl_args: named argument, see ssl module for more
informations

Overrides: object.__init__

load_filters(self)

source code 

Populate filters from self.filters. Must be called each time self.filters is updated.

perform(self, request)

source code 

perform the request. If an error happen it will first try to restart it