mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
This commit is contained in:
parent
b3f55f4a70
commit
5a650a253c
3 changed files with 102 additions and 17 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue