]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
actually close files
authorPhilip Jenvey <pjenvey@underboss.org>
Thu, 3 Dec 2009 02:40:13 +0000 (02:40 +0000)
committerPhilip Jenvey <pjenvey@underboss.org>
Thu, 3 Dec 2009 02:40:13 +0000 (02:40 +0000)
Lib/urllib.py

index db8e6160d45088ceee26822ae71b3c007a8f5ff2..1c31d48f9c314010a813f73b64bb67203d25b0a8 100644 (file)
@@ -231,7 +231,7 @@ class URLopener:
             try:
                 fp = self.open_local_file(url1)
                 hdrs = fp.info()
-                del fp
+                fp.close()
                 return url2pathname(splithost(url1)[1]), hdrs
             except IOError, msg:
                 pass
@@ -275,8 +275,6 @@ class URLopener:
                 tfp.close()
         finally:
             fp.close()
-        del fp
-        del tfp
 
         # raise exception if actual size does not match content-length header
         if size >= 0 and read < size:
@@ -1570,9 +1568,8 @@ def test(args=[]):
                 print '======'
                 for k in h.keys(): print k + ':', h[k]
                 print '======'
-            fp = open(fn, 'rb')
-            data = fp.read()
-            del fp
+            with open(fn, 'rb') as fp:
+                data = fp.read()
             if '\r' in data:
                 table = string.maketrans("", "")
                 data = data.translate(table, "\r")