10 import os |
10 import os |
11 import re |
11 import re |
12 import mimetypes |
12 import mimetypes |
13 |
13 |
14 from PyQt6.QtCore import ( |
14 from PyQt6.QtCore import ( |
15 QFile, QByteArray, QUrl, QCoreApplication, QBuffer, QIODevice |
15 QByteArray, QUrl, QCoreApplication, QBuffer, QIODevice |
16 ) |
16 ) |
17 from PyQt6.QtGui import QPixmap |
17 from PyQt6.QtGui import QPixmap |
18 |
18 |
19 |
19 |
20 WebBrowserDataDirectory = { |
20 WebBrowserDataDirectory = { |
31 @param filename name of the file |
31 @param filename name of the file |
32 @type str |
32 @type str |
33 @return contents of the file |
33 @return contents of the file |
34 @rtype str |
34 @rtype str |
35 """ |
35 """ |
36 return str(readAllFileByteContents(filename), encoding="utf-8") |
36 try: |
37 |
37 with open(filename, "r", encoding="utf-8") as f: |
38 |
38 return f.read() |
39 def readAllFileByteContents(filename): |
39 except OSError: |
40 """ |
40 return "" |
41 Function to read the bytes contents of the given file. |
|
42 |
|
43 @param filename name of the file |
|
44 @type str |
|
45 @return contents of the file |
|
46 @rtype str |
|
47 """ |
|
48 dataFile = QFile(filename) |
|
49 if filename and dataFile.open(QIODevice.OpenModeFlag.ReadOnly): |
|
50 contents = dataFile.readAll() |
|
51 dataFile.close() |
|
52 return contents |
|
53 |
|
54 return QByteArray() |
|
55 |
41 |
56 |
42 |
57 def containsSpace(string): |
43 def containsSpace(string): |
58 """ |
44 """ |
59 Function to check, if a string contains whitespace characters. |
45 Function to check, if a string contains whitespace characters. |