Skip to content
Myr

pre_request hook

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

authored by Kenneth Reitz · committed by Kenneth Reitz · parent 8ef0e88 · Browse files · 2 files+16 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+16 added−4 removed

  • other:+16 added−4 removed

2 files+16 added−4 removed

modified:requests/hooks.py+2 added-2 removed
9 unmodified lines
1011``args``:12 A dictionary of the arguments being sent to Request().1314``pre-request``:14``pre_request``:15 The Request object, directly before being sent.1617``post-request``:17``post_request``:18 The Request object, directly after being sent.1920``response``:21 The response generated from a Request.
19 unmodified lines
modified:requests/models.py+14 added-2 removed
14 unmodified lines
15from urlparse import urlparse, urlunparse, urljoin16from datetime import datetime1718from .config import settings19from .hooks import dispatch_hook20from .monkeys import Request as _Request, HTTPBasicAuthHandler, HTTPForcedBasicAuthHandler, HTTPDigestAuthHandler, HTTPRedirectHandler21from .structures import CaseInsensitiveDict22from .packages.poster.encode import multipart_encode23from .packages.poster.streaminghttp import register_openers, get_handlers
12 unmodified lines
3637 def __init__(self,38 url=None, headers=dict(), files=None, method=None, data=dict(),39 params=dict(), auth=None, cookiejar=None, timeout=None, redirect=False,39 allow_redirects=False, proxies=None):40 allow_redirects=False, proxies=None, hooks=None):4142 #: Float describ the timeout of the request.43 # (Use socket.setdefaulttimeout() as fallback)44 self.timeout = timeout
48 unmodified lines
9394 #: True if Request has been sent.95 self.sent = False9697 #: Dictionary of event hook callbacks.98 self.hooks = hooks99100101 # Header manipulation and defaults.102103 if settings.accept_gzip:104 settings.base_headers.update({'Accept-Encoding': 'gzip'})
221 unmodified lines
326327 try:328 opener = self._get_opener()329 try:330331 # pre-request hook.332 self.__dict__.update(333 dispatch_hook('pre_request',334 self.hooks, self.__dict__)335 )336337 resp = opener(req, timeout=self.timeout)338339 except TypeError, err:340 # timeout argument is new since Python v2.6329 if not "timeout" in str(err):341 if not 'timeout' in str(err):342 raise343344 if settings.timeout_fallback:345 # fall-back and use global socket timeout (This is not thread-safe!)
266 unmodified lines