WebBrowser/Tools/WebBrowserTools.py

branch
QtWebEngine
changeset 4725
b19ff70ba509
child 4741
f9e1adc69076
equal deleted inserted replaced
4717:5841f229baf7 4725:b19ff70ba509
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing tool functions for the web browser.
8 """
9
10 from __future__ import unicode_literals
11 try:
12 str = unicode # __IGNORE_EXCEPTION__
13 except NameError:
14 pass
15
16 from PyQt5.QtCore import QFile, QByteArray
17
18
19 def readAllFileContents(filename):
20 """
21 Function to read the string contents of the given file.
22
23 @param filename name of the file
24 @type str
25 @return contents of the file
26 @rtype str
27 """
28 return str(readAllFileByteContents(filename), encoding="utf-8")
29
30
31 def readAllFileByteContents(filename):
32 """
33 Function to read the bytes contents of the given file.
34
35 @param filename name of the file
36 @type str
37 @return contents of the file
38 @rtype str
39 """
40 dataFile = QFile(filename)
41 if filename and dataFile.open(QFile.ReadOnly):
42 contents = dataFile.readAll()
43 dataFile.close()
44 return contents
45
46 return QByteArray()

eric ide

mercurial