Skip to content

Commit

Permalink
Do not set expected to new IncompleteRead
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-v committed Feb 10, 2025
1 parent 74f3f9f commit 33f7d77
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ def read1(self, n=-1):
if not result and n:
self._close_conn()
if self.length:
raise IncompleteRead(result, self.length)
raise IncompleteRead(result)
elif self.length is not None:
self.length -= len(result)
if not self.length:
Expand Down Expand Up @@ -694,7 +694,7 @@ def readline(self, limit=-1):
if not result and limit:
self._close_conn()
if self.length:
raise IncompleteRead(result, self.length)
raise IncompleteRead(result)
elif self.length is not None:
self.length -= len(result)
if not self.length:
Expand Down
13 changes: 8 additions & 5 deletions Lib/test/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ class ExtendedReadTestContentLengthKnown(ExtendedReadTest):
_header, _body = ExtendedReadTest.lines.split('\r\n\r\n', 1)
lines = _header + f'\r\nContent-Length: {len(_body)}\r\n\r\n' + _body

def _test_incomplete_read(self, read_meth):
def _test_incomplete_read(self, read_meth, expected_none):
resp = self.resp
# Reduce the size of content the response object will read to
# cause the incomplete read.
Expand All @@ -1663,17 +1663,20 @@ def _test_incomplete_read(self, read_meth):
else:
expected_partial = b""
self.assertEqual(exception.partial, expected_partial)
self.assertEqual(exception.expected, 1)
if expected_none:
self.assertIsNone(exception.expected)
else:
self.assertEqual(exception.expected, 1)
self.assertTrue(resp.isclosed())

def test_read_incomplete_read(self):
self._test_incomplete_read(self.resp.read)
self._test_incomplete_read(self.resp.read, expected_none=False)

def test_read1_incomplete_read(self):
self._test_incomplete_read(self.resp.read1)
self._test_incomplete_read(self.resp.read1, expected_none=True)

def test_readline_incomplete_read(self):
self._test_incomplete_read(self.resp.readline)
self._test_incomplete_read(self.resp.readline, expected_none=True)


class ExtendedReadTestChunked(ExtendedReadTest):
Expand Down

0 comments on commit 33f7d77

Please sign in to comment.