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
Provenance
- Commit
4a9f357- Tree
421674d- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
2acce42
4 files changed+15 added−27 removed
modified:requests/__init__.py+11 added
56 unmodified lines57 from .exceptions import (58 RequestException, Timeout, URLRequired,59 TooManyRedirects, HTTPError, ConnectionError60 )61+62+# Set default logging handler to avoid "No handler found" warnings.63+import logging64+try: # Python 2.7+65+ from logging import NullHandler66+except ImportError:67+ class NullHandler(logging.Handler):68+ def emit(self, record):69+ pass70+71+logging.getLogger(__name__).addHandler(NullHandler())modified:requests/defaults.py-1 removed
36 unmodified lines37 defaults['max_retries'] = 038 defaults['keep_alive'] = True39 defaults['encode_uri'] = True40 defaults['trust_env'] = True41-defaults['store_cookies'] = True41 defaults['support_http0.9'] = Truemodified:requests/models.py+4 added-4 removed
8 unmodified lines9 10 import os11 import socket12 import collections13+import logging14+15 from datetime import datetime16 from io import BytesIO17 18 from .hooks import dispatch_hook, HOOKS23 unmodified lines42 43 REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)44 CONTENT_CHUNK_SIZE = 10 * 102445 46+log = logging.getLogger(__name__)47 48 class Request(object):49 """The :class:`Request <Request>` object. It carries out all functionality50 of Requests. Recommended interface is with the Requests functions.454 unmodified lines505 r = dispatch_hook('pre_request', self.hooks, self)506 self.__dict__.update(r.__dict__)507 508 # 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))510 511 # 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 linesmodified:tests/test_cookies.py-22 removed
102 unmodified lines103 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, {})106 107- def test_disabled_cookie_persistence(self):108- """Test that cookies are not persisted when configured accordingly."""109-110- config = {'store_cookies': False}111-112- # 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)115-116- # 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")122-123- # 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'], {})128-107 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.cookies134 unmodified lines