Skip to content
Myr

Revert "Revert "Make safe_mode play nice with timeout (fixes #312)""

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

This reverts commit 91766548d10cd5ebf46aba376f9e000263285875.

authored by Ori Livneh · committed by Ori Livneh · parent 9176654 · Browse files · 2 files+16 added−3 removed
This commit

State

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

Diff stats

2 files+16 added−3 removed

  • other:+16 added−3 removed

2 files+16 added−3 removed

modified:requests/models.py+5 added-3 removed
436 unmodified lines
437438 # Attach Cookie header to request.439 self.headers['Cookie'] = cookie_header440441 # If the request fails but exceptions are suppressed,442 # we'll build a blank response.443 r = None444445 try:446 # Send the request.447 r = conn.urlopen(448 method=self.method,
12 unmodified lines
461462 except MaxRetryError, e:463 if not self.config.get('safe_mode', False):464 raise ConnectionError(e)461 else:462 r = None465466 except (_SSLError, _HTTPError), e:467 if not self.config.get('safe_mode', False):468 raise Timeout('Request timed out.')
129 unmodified lines
598599 def generate():600 chunk = []601600 while 1:602 while True:603 c = self.raw.read(1)604 if not c:605 break606
90 unmodified lines
modified:test_requests.py+11 added
617 unmodified lines
618 # Make sure iter_lines doesn't chop the trailing bit619 lines = '\n'.join(r.iter_lines())620 self.assertEqual(lines, quote)621622 def test_timeout(self):623624 # When not in safe mode, should raise Timeout exception625 with self.assertRaises(requests.exceptions.Timeout):626 r = requests.get(httpbin('stream', '1000'), timeout=0.0001)627628 # In safe mode, should return a blank response629 r = requests.get(httpbin('stream', '1000'), timeout=0.0001,630 config=dict(safe_mode=True))631 self.assertIsNone(r.content)632633634if __name__ == '__main__':635 unittest.main()