Skip to content

Commit 0299d0d

Browse files
committed
actually close files
1 parent 2627553 commit 0299d0d

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

Lib/urllib.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def retrieve(self, url, filename=None, reporthook=None, data=None):
231231
try:
232232
fp = self.open_local_file(url1)
233233
hdrs = fp.info()
234-
del fp
234+
fp.close()
235235
return url2pathname(splithost(url1)[1]), hdrs
236236
except IOError, msg:
237237
pass
@@ -275,8 +275,6 @@ def retrieve(self, url, filename=None, reporthook=None, data=None):
275275
tfp.close()
276276
finally:
277277
fp.close()
278-
del fp
279-
del tfp
280278

281279
# raise exception if actual size does not match content-length header
282280
if size >= 0 and read < size:
@@ -1570,9 +1568,8 @@ def test(args=[]):
15701568
print '======'
15711569
for k in h.keys(): print k + ':', h[k]
15721570
print '======'
1573-
fp = open(fn, 'rb')
1574-
data = fp.read()
1575-
del fp
1571+
with open(fn, 'rb') as fp:
1572+
data = fp.read()
15761573
if '\r' in data:
15771574
table = string.maketrans("", "")
15781575
data = data.translate(table, "\r")

0 commit comments

Comments
 (0)