def __init__(self, manager=None, allowed_methods=ALLOWED_METHODS, strip_script_name=True, **kwargs): self.allowed_methods = allowed_methods self.strip_script_name = strip_script_name self.client = Client(**kwargs)
def request(url, method='GET', body=None, headers=None, **kwargs): """ Quick shortcut method to pass a request :param url: str, url string :param method: str, by default GET. http verbs :param body: the body, could be a string, an iterator or a file-like object :param headers: dict or list of tupple, http headers 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 manager: the manager to use. By default we use the global one. :parama 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. :param ssl_args: ssl named arguments, See http://docs.python.org/library/ssl.html informations """ # detect credentials from url u = urlparse.urlparse(url) if u.username is not None: password = u.password or "" filters = kwargs.get('filters') or [] url = urlparse.urlunparse((u.scheme, u.netloc.split("@")[-1], u.path, u.params, u.query, u.fragment)) filters.append(BasicAuth(u.username, password)) kwargs['filters'] = filters http_client = Client(**kwargs) return http_client.request(url, method=method, body=body, headers=headers)
def __init__(self, uri, **client_opts): """Constructor for a `Resource` object. Resource represent an HTTP resource. - uri: str, full uri to the server. - client_opts: `restkit.client.Client` Options """ client_opts = client_opts or {} self.initial = dict( uri = uri, client_opts = client_opts.copy() ) # set default response_class if self.response_class is not None and \ not 'response_class' in client_opts: client_opts['response_class'] = self.response_class self.filters = client_opts.get('filters') or [] self.uri = uri if self.basic_auth_url: # detect credentials from url u = urlparse.urlparse(uri) if u.username: password = u.password or "" # add filters filters = copy(self.filters) filters.append(BasicAuth(u.username, password)) client_opts['filters'] = filters # update uri self.uri = urlparse.urlunparse((u.scheme, u.netloc.split("@")[-1], u.path, u.params, u.query, u.fragment)) self.client_opts = client_opts self.client = Client(**self.client_opts)
def run(): cli = Client(timeout=300) func(self.url, cli)