mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Fixes issue #16409: The reporthook callback made by the legacy
urllib.request.urlretrieve API now properly supplies a constant non-zero block_size as it did in Python 3.2 and 2.7. This matches the behavior of urllib.request.URLopener.retrieve.
This commit is contained in:
parent
296c2fd065
commit
6b0bdab429
4 changed files with 39 additions and 7 deletions
|
@ -208,7 +208,7 @@ def urlretrieve(url, filename=None, reporthook=None, data=None):
|
|||
size = int(headers["Content-Length"])
|
||||
|
||||
if reporthook:
|
||||
reporthook(blocknum, 0, size)
|
||||
reporthook(blocknum, bs, size)
|
||||
|
||||
while True:
|
||||
block = fp.read(bs)
|
||||
|
@ -218,7 +218,7 @@ def urlretrieve(url, filename=None, reporthook=None, data=None):
|
|||
tfp.write(block)
|
||||
blocknum += 1
|
||||
if reporthook:
|
||||
reporthook(blocknum, len(block), size)
|
||||
reporthook(blocknum, bs, size)
|
||||
|
||||
if size >= 0 and read < size:
|
||||
raise ContentTooShortError(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue