patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve

This commit is contained in:
Georg Brandl 2005-08-26 08:51:34 +00:00
parent b3f55f4a70
commit 5a650a253c
3 changed files with 102 additions and 17 deletions

View file

@ -234,19 +234,17 @@ class URLopener:
bs = 1024*8
size = -1
read = 0
blocknum = 1
blocknum = 0
if reporthook:
if "content-length" in headers:
size = int(headers["Content-Length"])
reporthook(0, bs, size)
block = fp.read(bs)
read += len(block)
if reporthook:
reporthook(1, bs, size)
while block:
tfp.write(block)
reporthook(blocknum, bs, size)
while 1:
block = fp.read(bs)
if block == "":
break
read += len(block)
tfp.write(block)
blocknum += 1
if reporthook:
reporthook(blocknum, bs, size)