Skip to content
Myr

Allow for exceptions from tell()

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

authored by Cory Benfield · committed by Cory Benfield · parent 4f378b0 · Browse files · 2 files+20 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

2 files+20 added−2 removed

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

2 files+20 added−2 removed

modified:requests/utils.py+6 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.91 current_position = 09293 return max(0, total_length - current_position)9495
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()) == 5484950class TestGetEnvironProxies:51 """Ensures that IP addresses are correctly matches with ranges52 in no_proxy variable."""53
191 unmodified lines