Skip to content
Myr

Merge pull request #3036 from Lukasa/issue/3035

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

Allow for exceptions from tell()

authored by Ian Cordasco · committed by Ian Cordasco · parents 3a26d13, 90a166d · Browse files · 3 files+24 added−2 removed
This commit

State

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

Diff stats

3 files+24 added−2 removed

  • tests:+14 added−1 removed
  • other:+10 added−1 removed

3 files+24 added−2 removed

modified:requests/utils.py+8 added-1 removed
81 unmodified lines
82 FileModeWarning83 )8485 if hasattr(o, 'tell'):86 try:86 current_position = o.tell()87 current_position = o.tell()88 except (OSError, IOError):89 # This can happen in some weird situations, such as when the file90 # is actually a special file descriptor like stdin. In this91 # instance, we don't know what the length is, so set it to zero and92 # let requests chunk it instead.93 current_position = total_length9495 return max(0, total_length - current_position)9697
631 unmodified lines
modified:tests/test_utils.py+14 added-1 removed
13 unmodified lines
14from .compat import StringIO, cStringIO151617class TestSuperLen:1818 @pytest.mark.parametrize(19 'stream, value', (20 (StringIO.StringIO, 'Test'),21 (BytesIO, b'Test'),
9 unmodified lines
31 s = StringIO.StringIO()32 s.write('foobarbogus')33 assert super_len(s) == 03435 @pytest.mark.parametrize('error', [IOError, OSError])36 def test_super_len_handles_files_raising_weird_errors_in_tell(self, error):37 """38 If tell() raises errors, assume the cursor is at position zero.39 """40 class BoomFile(object):41 def __len__(self):42 return 54344 def tell(self):45 raise error()4647 assert super_len(BoomFile()) == 0484950class TestGetEnvironProxies:51 """Ensures that IP addresses are correctly matches with ranges52 in no_proxy variable."""53
191 unmodified lines
modified:HISTORY.rst+2 added
7 unmodified lines
89**Bugfixes**1011- Don't use redirect_cache if allow_redirects=False12- When passed objects that throw exceptions from ``tell()``, send them via13 chunked transfer encoding instead of failing.14152.9.1 (2015-12-21)16++++++++++++++++++17
1122 unmodified lines