eric7/WebBrowser/Tools/WebBrowserTools.py

branch
eric7
changeset 9162
8b75b1668583
parent 8881
54e42bc2437a
child 9167
2d2b9a26e904
--- a/eric7/WebBrowser/Tools/WebBrowserTools.py	Mon Jun 20 13:25:14 2022 +0200
+++ b/eric7/WebBrowser/Tools/WebBrowserTools.py	Mon Jun 20 19:47:39 2022 +0200
@@ -12,7 +12,7 @@
 import mimetypes
 
 from PyQt6.QtCore import (
-    QFile, QByteArray, QUrl, QCoreApplication, QBuffer, QIODevice
+    QByteArray, QUrl, QCoreApplication, QBuffer, QIODevice
 )
 from PyQt6.QtGui import QPixmap
 
@@ -33,25 +33,11 @@
     @return contents of the file
     @rtype str
     """
-    return str(readAllFileByteContents(filename), encoding="utf-8")
-
-
-def readAllFileByteContents(filename):
-    """
-    Function to read the bytes contents of the given file.
-    
-    @param filename name of the file
-    @type str
-    @return contents of the file
-    @rtype str
-    """
-    dataFile = QFile(filename)
-    if filename and dataFile.open(QIODevice.OpenModeFlag.ReadOnly):
-        contents = dataFile.readAll()
-        dataFile.close()
-        return contents
-    
-    return QByteArray()
+    try:
+        with open(filename, "r", encoding="utf-8") as f:
+            return f.read()
+    except OSError:
+        return ""
 
 
 def containsSpace(string):

eric ide

mercurial