eric6/WebBrowser/GreaseMonkey/GreaseMonkeyDownloader.py

changeset 7785
9978016560ec
parent 7781
607a6098cb44
child 7836
2f0d208b8137
--- a/eric6/WebBrowser/GreaseMonkey/GreaseMonkeyDownloader.py	Tue Oct 13 19:02:26 2020 +0200
+++ b/eric6/WebBrowser/GreaseMonkey/GreaseMonkeyDownloader.py	Wed Oct 14 17:50:39 2020 +0200
@@ -88,12 +88,11 @@
             self.__fileName = WebBrowserTools.ensureUniqueFilename(filePath)
         
         try:
-            f = open(self.__fileName, "w", encoding="utf-8")
+            with open(self.__fileName, "w", encoding="utf-8") as f:
+                f.write(response)
         except (IOError, OSError):
             self.error.emit()
             return
-        f.write(response)
-        f.close()
         
         self.finished.emit(self.__fileName)
     
@@ -144,12 +143,11 @@
                     self.__fileName)
         
         try:
-            f = open(self.__fileName, "w", encoding="utf-8")
+            with open(self.__fileName, "w", encoding="utf-8") as f:
+                f.write(response)
         except (IOError, OSError):
             self.error.emit()
             return
-        f.write(response)
-        f.close()
         
         settings.setValue(self.__reply.request().url().toString(),
                           QFileInfo(self.__fileName).fileName())

eric ide

mercurial