Patches item #810023, was opened at 2003-09-21 07:13
Message generated for change (Comment added) made by birkenfeld
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=810023&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: Python 2.4
>Status: Closed
>Resolution: Accepted
Priority: 5
Submitted By: J. Lewis Muir (jlmuir)
Assigned to: Reinhold Birkenfeld (birkenfeld)
Summary: Fix for off-by-one bug in urllib.URLopener.retrieve
Initial Comment:
This patch fixes an off-by-one bug in the reporthook part of
urllib.URLopener.retrieve and adds test cases to verify the
fix.
The retrieve method reports reading one more block than it
actually does. Here's an example. The file is empty. I expect
the initial reporthook call on establishment of the network
connection but not an additional call since the file is empty
(no block was read):
>>> import urllib
>>> def reporter(count, blockSize, fileSize):
... print "c: %i, bs: %i, fs: %i" % (count, blockSize,
fileSize)
...
>>> srcFile = file("/tmp/empty.txt", "wb")
>>> srcFile.close()
>>> urllib.urlretrieve("file:///tmp/empty.txt",
"/tmp/new-
empty.txt", reporter)
c: 0, bs: 8192, fs: 0
c: 1, bs: 8192, fs: 0
('/tmp/new-empty.txt', <mimetools.Message instance at
0x5a4f58>)
>>>
As a second example, if the file contains 1 byte, the retrieve
method claims it read 2 blocks when it really only read 1:
>>> srcFile = file("/tmp/empty.txt", "wb")
>>> srcFile.write("x")
>>> srcFile.close()
>>> urllib.urlretrieve("file:///tmp/empty.txt",
"/tmp/new-
empty.txt", reporter)
c: 0, bs: 8192, fs: 1
c: 1, bs: 8192, fs: 1
c: 2, bs: 8192, fs: 1
('/tmp/new-empty.txt', <mimetools.Message instance at
0x5a50d0>)
>>>
This patch also includes some changes to
test_urllib.urlretrieve_FileTests (where I added the test
cases) to support creating more than one temporary file and
making sure any created temporary files get deleted when
the test case fixture is torn down.
----------------------------------------------------------------------
>Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-08-26 10:52
Message:
Logged In: YES
user_id=1188172
Patch looks good, committed as
Lib/urllib.py r1.168 r1.165.2.1
Lib/test/test_urllib.py r1.17 r1.16.4.1
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2005-08-26 10:20
Message:
Logged In: YES
user_id=80475
Reinhold, do you have time for this one?
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2004-12-21 01:29
Message:
Logged In: YES
user_id=80475
Titus, I'm having difficulty with your link, please attach
the revised patch or just email it to me (python at rcn.com).
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2004-12-20 04:55
Message:
Logged In: YES
user_id=80475
Will review and apply after Xmas vacation.
----------------------------------------------------------------------
Comment By: Titus Brown (titus)
Date: 2004-12-19 09:51
Message:
Logged In: YES
user_id=23486
Patch needed slight modification to work against current HEAD; new
patch at
http://issola.caltech.edu/~t/transfer/transfer/patch-810023-
reporthook.diff
The new regression tests look reasonable. I verified that the new
regression tests FAILED against old urllib.py, and worked against patched
urllib.py. Recommend apply.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=810023&group_id=5470
_______________________________________________
Patches mailing list
[email protected]
http://mail.python.org/mailman/listinfo/patches