Skip to content
Myr

logging handlers

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

Closes #971

authored by Kenneth Reitz · committed by Kenneth Reitz · parent 2acce42 · Browse files · 4 files+15 added−27 removed
This commit

State

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

Diff stats

4 files+15 added−27 removed

  • tests:+0 added−22 removed
  • other:+15 added−5 removed

4 files+15 added−27 removed

modified:requests/__init__.py+11 added
56 unmodified lines
57from .exceptions import (58 RequestException, Timeout, URLRequired,59 TooManyRedirects, HTTPError, ConnectionError60)6162# Set default logging handler to avoid "No handler found" warnings.63import logging64try: # Python 2.7+65 from logging import NullHandler66except ImportError:67 class NullHandler(logging.Handler):68 def emit(self, record):69 pass7071logging.getLogger(__name__).addHandler(NullHandler())
modified:requests/defaults.py-1 removed
36 unmodified lines
37defaults['max_retries'] = 038defaults['keep_alive'] = True39defaults['encode_uri'] = True40defaults['trust_env'] = True41defaults['store_cookies'] = True41defaults['support_http0.9'] = True
modified:requests/models.py+4 added-4 removed
8 unmodified lines
910import os11import socket12import collections13import logging1415from datetime import datetime16from io import BytesIO1718from .hooks import dispatch_hook, HOOKS
23 unmodified lines
4243REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)44CONTENT_CHUNK_SIZE = 10 * 10244546log = logging.getLogger(__name__)4748class Request(object):49 """The :class:`Request <Request>` object. It carries out all functionality50 of Requests. Recommended interface is with the Requests functions.
454 unmodified lines
505 r = dispatch_hook('pre_request', self.hooks, self)506 self.__dict__.update(r.__dict__)507508 # Logging506 if self.config.get('verbose'):507 self.config.get('verbose').write('%s %s %s\n' % (508 datetime.now().isoformat(), self.method, url509 ))509 log.info('Sending %s: %s' % (self, url))510511 # Use .netrc auth if none was provided.512 if not self.auth and self.config.get('trust_env'):513 self.auth = get_netrc_auth(url)
407 unmodified lines
modified:tests/test_cookies.py-22 removed
102 unmodified lines
103 insecure_resp = requests.get('http://httpbin.org/cookies', cookies=cookies)104 insecure_cookies_sent = json.loads(insecure_resp.text)['cookies']105 self.assertEqual(insecure_cookies_sent, {})106107 def test_disabled_cookie_persistence(self):108 """Test that cookies are not persisted when configured accordingly."""109110 config = {'store_cookies': False}111112 # Check the case when no cookie is passed as part of the request and the one in response is ignored113 cookies = requests.get(httpbin('cookies', 'set', 'key', 'value'), config=config).cookies114 self.assertTrue(cookies.get("key") is None)115116 # Test that the cookies passed while making the request still gets used and is available in response object.117 # only the ones received from server is not saved118 cookies_2 = requests.get(httpbin('cookies', 'set', 'key', 'value'), config=config,\119 cookies={"key_2": "value_2"}).cookies120 self.assertEqual(len(cookies_2), 1)121 self.assertEqual(cookies_2.get("key_2"), "value_2")122123 # Use the session and make sure that the received cookie is not used in subsequent calls124 s = requests.session()125 s.get(httpbin('cookies', 'set', 'key', 'value'), config=config)126 r = s.get(httpbin('cookies'))127 self.assertEqual(json.loads(r.text)['cookies'], {})128107 def test_jar_utility_functions(self):108 """Test utility functions such as list_domains, list_paths, multiple_domains."""109 r = requests.get("http://github.com")110 c = r.cookies
134 unmodified lines