eric6/UI/Previewers/PreviewerHTML.py

changeset 7785
9978016560ec
parent 7781
607a6098cb44
child 7824
096b3ebc1409
child 7836
2f0d208b8137
diff -r 3257703e10c5 -r 9978016560ec eric6/UI/Previewers/PreviewerHTML.py
--- a/eric6/UI/Previewers/PreviewerHTML.py	Tue Oct 13 19:02:26 2020 +0200
+++ b/eric6/UI/Previewers/PreviewerHTML.py	Wed Oct 14 17:50:39 2020 +0200
@@ -497,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 = ""
@@ -585,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',
@@ -603,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