diff options
author | Georg Brandl <georg@python.org> | 2005-08-26 08:51:34 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2005-08-26 08:51:34 (GMT) |
commit | 5a650a253c89bf6a491fc67c441530969ee4bda8 (patch) | |
tree | c80a0e9eaaf700d58ad021f4fa95730e02c6c12e /Lib/urllib.py | |
parent | b3f55f4a706113f24386afd4bb1262b44a1c70c0 (diff) | |
download | cpython-5a650a253c89bf6a491fc67c441530969ee4bda8.zip cpython-5a650a253c89bf6a491fc67c441530969ee4bda8.tar.gz cpython-5a650a253c89bf6a491fc67c441530969ee4bda8.tar.bz2 |
patch [ 810023 ] Fix for off-by-one bug in urllib.URLopener.retrieve
Diffstat (limited to 'Lib/urllib.py')
-rw-r--r-- | Lib/urllib.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py index 4f1ebdd..1daa49d 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -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) |