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:
Gregory P. Smith 2012-11-10 13:43:44 -08:00
parent 296c2fd065
commit 6b0bdab429
4 changed files with 39 additions and 7 deletions

View file

@ -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(