mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Merged revisions 70521 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r70521 | benjamin.peterson | 2009-03-22 12:45:11 -0500 (Sun, 22 Mar 2009) | 1 line close the file even if an exception occurs #5536 ........
This commit is contained in:
parent
218f462a0f
commit
373498fc67
2 changed files with 42 additions and 35 deletions
|
@ -233,6 +233,7 @@ class URLopener:
|
||||||
except IOError, msg:
|
except IOError, msg:
|
||||||
pass
|
pass
|
||||||
fp = self.open(url, data)
|
fp = self.open(url, data)
|
||||||
|
try:
|
||||||
headers = fp.info()
|
headers = fp.info()
|
||||||
if filename:
|
if filename:
|
||||||
tfp = open(filename, 'wb')
|
tfp = open(filename, 'wb')
|
||||||
|
@ -246,6 +247,7 @@ class URLopener:
|
||||||
(fd, filename) = tempfile.mkstemp(suffix)
|
(fd, filename) = tempfile.mkstemp(suffix)
|
||||||
self.__tempfiles.append(filename)
|
self.__tempfiles.append(filename)
|
||||||
tfp = os.fdopen(fd, 'wb')
|
tfp = os.fdopen(fd, 'wb')
|
||||||
|
try:
|
||||||
result = filename, headers
|
result = filename, headers
|
||||||
if self.tempcache is not None:
|
if self.tempcache is not None:
|
||||||
self.tempcache[url] = result
|
self.tempcache[url] = result
|
||||||
|
@ -266,8 +268,10 @@ class URLopener:
|
||||||
blocknum += 1
|
blocknum += 1
|
||||||
if reporthook:
|
if reporthook:
|
||||||
reporthook(blocknum, bs, size)
|
reporthook(blocknum, bs, size)
|
||||||
fp.close()
|
finally:
|
||||||
tfp.close()
|
tfp.close()
|
||||||
|
finally:
|
||||||
|
fp.close()
|
||||||
del fp
|
del fp
|
||||||
del tfp
|
del tfp
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #5536: urllib.urlretrieve makes sure to close the file it's writing to
|
||||||
|
even if an exception occurs.
|
||||||
|
|
||||||
- Fix Decimal.__format__ bug that swapped the meanings of the '<' and
|
- Fix Decimal.__format__ bug that swapped the meanings of the '<' and
|
||||||
'>' alignment characters.
|
'>' alignment characters.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue