logging handlers
authorKenneth Reitz <me@kennethreitz.com>
Sat, 15 Dec 2012 04:51:53 +0000 (23:51 -0500)
committerKenneth Reitz <me@kennethreitz.com>
Sat, 15 Dec 2012 04:51:53 +0000 (23:51 -0500)
Closes #971

requests/__init__.py
requests/defaults.py
requests/models.py
tests/test_cookies.py

index 8e5b6b0..af2e5b1 100644 (file)
@@ -58,3 +58,14 @@ from .exceptions import (
     RequestException, Timeout, URLRequired,
     TooManyRedirects, HTTPError, ConnectionError
 )
+
+# Set default logging handler to avoid "No handler found" warnings.
+import logging
+try:  # Python 2.7+
+    from logging import NullHandler
+except ImportError:
+    class NullHandler(logging.Handler):
+        def emit(self, record):
+            pass
+
+logging.getLogger(__name__).addHandler(NullHandler())
index d8bcb29..0d4e8e7 100644 (file)
@@ -38,5 +38,4 @@ defaults['max_retries'] = 0
 defaults['keep_alive'] = True
 defaults['encode_uri'] = True
 defaults['trust_env'] = True
-defaults['store_cookies'] = True
 defaults['support_http0.9'] = True
index d7a910e..4527f6c 100644 (file)
@@ -10,6 +10,8 @@ This module contains the primary objects that power Requests.
 import os
 import socket
 import collections
+import logging
+
 from datetime import datetime
 from io import BytesIO
 
@@ -41,6 +43,7 @@ from .compat import (
 REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)
 CONTENT_CHUNK_SIZE = 10 * 1024
 
+log = logging.getLogger(__name__)
 
 class Request(object):
     """The :class:`Request <Request>` object. It carries out all functionality
@@ -503,10 +506,7 @@ class Request(object):
         self.__dict__.update(r.__dict__)
 
         # Logging
-        if self.config.get('verbose'):
-            self.config.get('verbose').write('%s   %s   %s\n' % (
-                datetime.now().isoformat(), self.method, url
-            ))
+        log.info('Sending %s: %s' % (self, url))
 
         # Use .netrc auth if none was provided.
         if not self.auth and self.config.get('trust_env'):
index e1c4203..90141a9 100755 (executable)
@@ -104,28 +104,6 @@ class CookieTests(TestBaseMixin, unittest.TestCase):
         insecure_cookies_sent = json.loads(insecure_resp.text)['cookies']
         self.assertEqual(insecure_cookies_sent, {})
 
-    def test_disabled_cookie_persistence(self):
-        """Test that cookies are not persisted when configured accordingly."""
-
-        config = {'store_cookies': False}
-
-        # Check the case when no cookie is passed as part of the request and the one in response is ignored
-        cookies = requests.get(httpbin('cookies', 'set', 'key', 'value'), config=config).cookies
-        self.assertTrue(cookies.get("key") is None)
-
-        # Test that the cookies passed while making the request still gets used and is available in response object.
-        # only the ones received from server is not saved
-        cookies_2 = requests.get(httpbin('cookies', 'set', 'key', 'value'), config=config,\
-                                                cookies={"key_2": "value_2"}).cookies
-        self.assertEqual(len(cookies_2), 1)
-        self.assertEqual(cookies_2.get("key_2"), "value_2")
-
-        # Use the session and make sure that the received cookie is not used in subsequent calls
-        s = requests.session()
-        s.get(httpbin('cookies', 'set', 'key', 'value'), config=config)
-        r = s.get(httpbin('cookies'))
-        self.assertEqual(json.loads(r.text)['cookies'], {})
-
     def test_jar_utility_functions(self):
         """Test utility functions such as list_domains, list_paths, multiple_domains."""
         r = requests.get("http://github.com")