remove safe mode
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 1607a6a · Browse files · 3 files·+0 added−45 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+0 added−45 removed
- other:+0 added−45 removed
Provenance
- Commit
f553857- Tree
5b53c24- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
1607a6a
3 files changed+0 added−45 removed
modified:requests/defaults.py-3 removed
37 unmodified lines38 defaults['max_redirects'] = 3039 defaults['pool_connections'] = 1040 defaults['pool_maxsize'] = 1041 defaults['max_retries'] = 042-defaults['danger_mode'] = False43-defaults['safe_mode'] = False44-defaults['strict_mode'] = False42 defaults['keep_alive'] = True43 defaults['encode_uri'] = True44 defaults['trust_env'] = True45 defaults['store_cookies'] = Truedeleted:requests/safe_mode.py-40 removed
1-# -*- coding: utf-8 -*-2-3-"""4-requests.safe_mode5-~~~~~~~~~~~~6-7-This module contains a decorator that implements safe_mode.8-9-:copyright: (c) 2012 by Kenneth Reitz.10-:license: ISC, see LICENSE for more details.11-12-"""13-14-from .models import Response15-from .packages.urllib3.response import HTTPResponse16-from .exceptions import RequestException, ConnectionError, HTTPError17-import socket18-19-20-def catch_exceptions_if_in_safe_mode(function):21- """New implementation of safe_mode. We catch all exceptions at the Session level22- and then return a blank Response object with the error field filled. This decorator23- wraps Session._send_request() in sessions.py.24- """25-26- def wrapped(*args, **kwargs):27- # if save_mode, we catch exceptions and fill error field28- if (kwargs.get('config') and kwargs.get('config').get('safe_mode')) or (kwargs.get('session')29- and kwargs.get('session').config.get('safe_mode')):30- try:31- return function(*args, **kwargs)32- except (RequestException, ConnectionError, HTTPError,33- socket.timeout, socket.gaierror) as e:34- r = Response()35- r.error = e36- r.raw = HTTPResponse() # otherwise, tests fail37- r.status_code = 0 # with this status_code, content returns None38- return r39- return function(*args, **kwargs)40- return wrappedmodified:requests/sessions.py-2 removed
15 unmodified lines16 from .models import Request17 from .hooks import dispatch_hook18 from .utils import header_expand, from_key_val_list19 from .packages.urllib3.poolmanager import PoolManager20-from .safe_mode import catch_exceptions_if_in_safe_mode20 21 22 def merge_kwargs(local_kwarg, default_kwarg):23 """Merges kwarg dictionaries.242 unmodified lines266 267 # Send the HTTP Request.268 return self._send_request(r, **args)269 271- @catch_exceptions_if_in_safe_mode270 def _send_request(self, r, **kwargs):271 # Send the request.272 r.send(prefetch=kwargs.get("prefetch"))273 86 unmodified lines