Skip to content

Commit 4766237

Browse files
GH-43374: Revert "GH-43374: Fix urlretrieve reporthook to report actual bytes r… (#143711)
Revert "GH-43374: Fix urlretrieve reporthook to report actual bytes read (#142653)" This reverts commit 68a01f9.
1 parent c559135 commit 4766237

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

Lib/test/test_urllib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ def hooktester(block_count, block_read_size, file_size, _report=report):
727727
self.assertEqual(report[0][2], 8193)
728728
self.assertEqual(report[0][1], 8192)
729729
self.assertEqual(report[1][1], 8192)
730-
self.assertEqual(report[2][1], 1) # last block only reads 1 byte
730+
self.assertEqual(report[2][1], 8192)
731731

732732

733733
class urlretrieve_HttpTests(unittest.TestCase, FakeHTTPMixin):

Lib/test/test_urllibnet.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,12 @@ def recording_reporthook(blocks, block_size, total_size):
219219
self.assertEqual(records[0][2], expected_size)
220220
self.assertEqual(records[-1][2], expected_size)
221221

222-
self.assertEqual(records[0][1], 8192,
223-
msg="first block size should be 8192 in %s" % records_repr)
224-
for block_num, block_size, total_size in records:
225-
self.assertLessEqual(block_size, 8192,
226-
msg="block size should be <= 8192 in %s" % records_repr)
227-
total_read = sum(block_size for _, block_size, _ in records[1:])
228-
self.assertEqual(total_read, expected_size,
229-
msg="sum of bytes read must equal total size in %s" % records_repr)
222+
block_sizes = {block_size for _, block_size, _ in records}
223+
self.assertEqual({records[0][1]}, block_sizes,
224+
msg="block sizes in %s must be equal" % records_repr)
225+
self.assertGreaterEqual(records[-1][0]*records[0][1], expected_size,
226+
msg="number of blocks * block size must be"
227+
" >= total size in %s" % records_repr)
230228

231229

232230
if __name__ == "__main__":

Lib/urllib/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def urlretrieve(url, filename=None, reporthook=None, data=None):
242242
tfp.write(block)
243243
blocknum += 1
244244
if reporthook:
245-
reporthook(blocknum, len(block), size)
245+
reporthook(blocknum, bs, size)
246246

247247
if size >= 0 and read < size:
248248
raise ContentTooShortError(

Misc/NEWS.d/next/Library/2025-12-12-23-17-10.gh-issue-43374.M6jGC5.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)