Skip to content
Myr

new hooks system

Before adoption: this commit came in with the history the project adopted, so no landing records it.

#118

authored by Kenneth Reitz · committed by Kenneth Reitz · parent fc04d8a · Browse files · 2 files+34 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+34 added−4 removed

  • other:+34 added−4 removed

2 files+34 added−4 removed

modified:requests/api.py+9 added-4 removed
10 unmodified lines
1112"""1314import config15from .models import Request, Response, AuthManager, AuthObject, auth_manager15from .models import Request, Response, AuthObject16from .status_codes import codes17from .hooks import dispatch_hook181920__all__ = ('request', 'get', 'head', 'post', 'patch', 'put', 'delete')2122def request(method, url,23 params=None, data=None, headers=None, cookies=None, files=None, auth=None,23 timeout=None, allow_redirects=False, proxies=None):24 timeout=None, allow_redirects=False, proxies=None, hooks=None):2526 """Constructs and sends a :class:`Request <models.Request>`. Returns :class:`Response <models.Response>` object.2728 :param method: method for the new :class:`Request` object.
8 unmodified lines
37 :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.38 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.39 """4040 r = Request(41 args = dict(42 method = method,43 url = url,44 data = data,45 params = params,46 headers = headers,47 cookiejar = cookies,48 files = files,48 auth = auth or auth_manager.get_auth(url),49 auth = auth,50 timeout = timeout or config.settings.timeout,51 allow_redirects = allow_redirects,52 proxies = proxies or config.settings.proxies53 )5455 args = dispatch_hook('args', hooks, args)5657 r = Request(**args)5859 r.send()6061 return r.response62
103 unmodified lines
added:requests/hooks.py+25 added
1# -*- coding: utf-8 -*-23"""4requests.hooks5~~~~~~~~~~~~~~67This module provides the capabilities for the Requests hooks system.8"""910import warnings1112def dispatch_hook(key, hooks, hook_data):13 """"""1415 hooks = hooks or dict()1617 if key in hooks:18 try:19 return hooks.get(key).__call__(hook_data) or hook_data2021 except Exception, why:22 warnings.warn(str(why))232425 return hook_data