[jhbuild] Close files when done in httpcache (GNOME bug 638188)



commit 3c0b66aebce41960856963016e3aa43a90d3045d
Author: Craig Keogh <cskeogh adam com au>
Date:   Thu Aug 25 21:30:14 2011 +0930

    Close files when done in httpcache (GNOME bug 638188)

 jhbuild/utils/httpcache.py |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/jhbuild/utils/httpcache.py b/jhbuild/utils/httpcache.py
index 17a6fb7..51c2248 100644
--- a/jhbuild/utils/httpcache.py
+++ b/jhbuild/utils/httpcache.py
@@ -137,9 +137,10 @@ class Cache:
 
             node = document.createTextNode('\n')
             document.documentElement.appendChild(node)
-        
-        document.writexml(open(cindex, 'w'))
+        fp = open(cindex, 'w')
+        document.writexml(fp)
         document.unlink()
+        fp.close()
 
     def _make_filename(self, uri):
         '''picks a unique name for a new entry in the cache.
@@ -210,7 +211,9 @@ class Cache:
                                response.headers.get('Last-Modified'),
                                response.headers.get('ETag'))
             filename = os.path.join(self.cachedir, entry.local)
-            open(filename, 'wb').write(data)
+            fp = open(filename, 'wb')
+            fp.write(data)
+            fp.close()
         except urllib2.HTTPError, e:
             if e.code == 304: # not modified; update validated
                 expires = e.hdrs.get('Expires')



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]