add eager mode for raising errors immediately

This commit is contained in:
Bryan Helmig
2012-01-04 22:08:01 -06:00
parent 4441697e49
commit 115b51e68c
4 changed files with 16 additions and 0 deletions
+1
View File
@@ -68,3 +68,4 @@ Patches and Suggestions
- Christopher Davis
- Ori Livneh
- Jason Emerick
- Bryan Helmig
+2
View File
@@ -15,6 +15,7 @@ Configurations:
:decode_unicode: Decode unicode responses automatically?
:keep_alive: Reuse HTTP Connections?
:max_retries: The number of times a request should be retried in the event of a connection failure.
:eager_mode: If true, Requests will raise errors immediately.
:safe_mode: If true, Requests will catch all errors.
:pool_maxsize: The maximium size of an HTTP connection pool.
:pool_connections: The number of active HTTP connection pools to use.
@@ -38,5 +39,6 @@ defaults['decode_unicode'] = True
defaults['pool_connections'] = 10
defaults['pool_maxsize'] = 10
defaults['max_retries'] = 0
defaults['eager_mode'] = False
defaults['safe_mode'] = False
defaults['keep_alive'] = True
+3
View File
@@ -525,6 +525,9 @@ class Request(object):
if prefetch:
# Save the response.
self.response.content
if self.config.get('eager_mode'):
self.response.raise_for_status()
return self.sent
+10
View File
@@ -279,6 +279,16 @@ class RequestsTestSuite(unittest.TestCase):
r.raise_for_status()
def test_default_status_raising(self):
config = {'eager_mode': True}
args = [httpbin('status', '404')]
kwargs = dict(config=config)
self.assertRaises(HTTPError, requests.get, *args, **kwargs)
r = requests.get(httpbin('status', '200'))
self.assertEqual(r.status_code, 200)
def test_decompress_gzip(self):
r = requests.get(httpbin('gzip'))