WebBrowser/Tools/WebBrowserTools.py

branch
QtWebEngine
changeset 4725
b19ff70ba509
child 4741
f9e1adc69076
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WebBrowser/Tools/WebBrowserTools.py	Sat Feb 06 17:43:59 2016 +0100
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing tool functions for the web browser.
+"""
+
+from __future__ import unicode_literals
+try:
+    str = unicode       # __IGNORE_EXCEPTION__
+except NameError:
+    pass
+
+from PyQt5.QtCore import QFile, QByteArray
+
+
+def readAllFileContents(filename):
+    """
+    Function to read the string contents of the given file.
+    
+    @param filename name of the file
+    @type str
+    @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(QFile.ReadOnly):
+        contents = dataFile.readAll()
+        dataFile.close()
+        return contents
+    
+    return QByteArray()

eric ide

mercurial