eric6/UI/Previewers/PreviewerHTML.py

branch
maintenance
changeset 7824
096b3ebc1409
parent 7737
5371a22cf2aa
parent 7785
9978016560ec
child 7850
e64b178499da
diff -r 10554f5fac78 -r 096b3ebc1409 eric6/UI/Previewers/PreviewerHTML.py
--- a/eric6/UI/Previewers/PreviewerHTML.py	Sat Oct 03 11:14:23 2020 +0200
+++ b/eric6/UI/Previewers/PreviewerHTML.py	Sun Nov 01 11:15:18 2020 +0100
@@ -7,7 +7,6 @@
 Module implementing a previewer widget for HTML, Markdown and ReST files.
 """
 
-
 import os
 import threading
 import re
@@ -314,7 +313,7 @@
         self.previewView.page().runJavaScript(
             script, resultCallback)
         
-        loop.exec_()
+        loop.exec()
         return resultDict["res"]
 
 
@@ -498,9 +497,8 @@
                 incFile = ""
             if os.path.exists(incFile):
                 try:
-                    f = open(incFile, "r")
-                    incTxt = f.read()
-                    f.close()
+                    with open(incFile, "r") as f:
+                        incTxt = f.read()
                 except (IOError, OSError):
                     # remove SSI include
                     incTxt = ""
@@ -586,10 +584,9 @@
         try:
             filename = 'sphinx_preview'
             basePath = os.path.join(srcTempDir, filename)
-            fh = open(basePath + '.rst', 'w', encoding='utf-8')
-            fh.write(text)
-            fh.close()
-
+            with open(basePath + '.rst', 'w', encoding='utf-8') as fh:
+                fh.write(text)
+            
             overrides = {'html_add_permalinks': False,
                          'html_copy_source': False,
                          'html_title': 'Sphinx preview',
@@ -604,9 +601,8 @@
             app.build(force_all=True, filenames=None)
 
             basePath = os.path.join(outTempDir, filename)
-            fh = open(basePath + '.html', 'r', encoding='utf-8')
-            html = fh.read()
-            fh.close()
+            with open(basePath + '.html', 'r', encoding='utf-8') as fh:
+                html = fh.read()
         finally:
             shutil.rmtree(srcTempDir)
             shutil.rmtree(outTempDir)

eric ide

mercurial