mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
actually close files
This commit is contained in:
parent
2627553afa
commit
0299d0d7f0
1 changed files with 3 additions and 6 deletions
|
|
@ -231,7 +231,7 @@ class URLopener:
|
||||||
try:
|
try:
|
||||||
fp = self.open_local_file(url1)
|
fp = self.open_local_file(url1)
|
||||||
hdrs = fp.info()
|
hdrs = fp.info()
|
||||||
del fp
|
fp.close()
|
||||||
return url2pathname(splithost(url1)[1]), hdrs
|
return url2pathname(splithost(url1)[1]), hdrs
|
||||||
except IOError, msg:
|
except IOError, msg:
|
||||||
pass
|
pass
|
||||||
|
|
@ -275,8 +275,6 @@ class URLopener:
|
||||||
tfp.close()
|
tfp.close()
|
||||||
finally:
|
finally:
|
||||||
fp.close()
|
fp.close()
|
||||||
del fp
|
|
||||||
del tfp
|
|
||||||
|
|
||||||
# raise exception if actual size does not match content-length header
|
# raise exception if actual size does not match content-length header
|
||||||
if size >= 0 and read < size:
|
if size >= 0 and read < size:
|
||||||
|
|
@ -1570,9 +1568,8 @@ def test(args=[]):
|
||||||
print '======'
|
print '======'
|
||||||
for k in h.keys(): print k + ':', h[k]
|
for k in h.keys(): print k + ':', h[k]
|
||||||
print '======'
|
print '======'
|
||||||
fp = open(fn, 'rb')
|
with open(fn, 'rb') as fp:
|
||||||
data = fp.read()
|
data = fp.read()
|
||||||
del fp
|
|
||||||
if '\r' in data:
|
if '\r' in data:
|
||||||
table = string.maketrans("", "")
|
table = string.maketrans("", "")
|
||||||
data = data.translate(table, "\r")
|
data = data.translate(table, "\r")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue