13 import re |
13 import re |
14 import stat |
14 import stat |
15 |
15 |
16 from PyQt6.QtCore import QEventLoop, QObject, pyqtSlot |
16 from PyQt6.QtCore import QEventLoop, QObject, pyqtSlot |
17 |
17 |
|
18 from eric7 import Utilities |
18 from eric7.RemoteServer.EricRequestCategory import EricRequestCategory |
19 from eric7.RemoteServer.EricRequestCategory import EricRequestCategory |
19 from eric7.SystemUtilities import FileSystemUtilities |
20 from eric7.SystemUtilities import FileSystemUtilities |
20 |
21 |
21 |
22 |
22 class EricServerFileSystemInterface(QObject): |
23 class EricServerFileSystemInterface(QObject): |
956 ) |
957 ) |
957 |
958 |
958 loop.exec() |
959 loop.exec() |
959 if not ok: |
960 if not ok: |
960 raise OSError(error) |
961 raise OSError(error) |
|
962 |
|
963 def readEncodedFile(self, filename, create=False): |
|
964 """ |
|
965 Function to read a file and decode its contents into proper text. |
|
966 |
|
967 @param filename name of the file to read |
|
968 @type str |
|
969 @param create flag indicating to create an empty file, if it does not exist |
|
970 (defaults to False) |
|
971 @type bool (optional) |
|
972 @return tuple of decoded text and encoding |
|
973 @rtype tuple of (str, str) |
|
974 """ |
|
975 data = self.readFile(filename, create=create) |
|
976 return Utilities.decode(data) |
|
977 |
|
978 def readEncodedFileWithEncoding(self, filename, encoding, create=False): |
|
979 """ |
|
980 Function to read a file and decode its contents into proper text. |
|
981 |
|
982 @param filename name of the file to read |
|
983 @type str |
|
984 @param encoding encoding to be used to read the file |
|
985 @type str |
|
986 @param create flag indicating to create an empty file, if it does not exist |
|
987 (defaults to False) |
|
988 @type bool (optional) |
|
989 @return tuple of decoded text and encoding |
|
990 @rtype tuple of (str, str) |
|
991 """ |
|
992 data = self.readFile(filename, create=create) |
|
993 return Utilities.decodeWithEncoding(data, encoding) |
|
994 |
|
995 def writeEncodedFile(self, filename, text, origEncoding, forcedEncoding="", withBackup=False): |
|
996 """ |
|
997 Function to write a file with properly encoded text. |
|
998 |
|
999 @param filename name of the file to read |
|
1000 @type str |
|
1001 @param text text to be written |
|
1002 @type str |
|
1003 @param origEncoding type of the original encoding |
|
1004 @type str |
|
1005 @param forcedEncoding encoding to be used for writing, if no coding |
|
1006 line is present (defaults to "") |
|
1007 @type str (optional) |
|
1008 @param withBackup flag indicating to create a backup file first |
|
1009 (defaults to False) |
|
1010 @type bool (optional) |
|
1011 @return encoding used for writing the file |
|
1012 @rtype str |
|
1013 """ |
|
1014 data, encoding = Utilities.encode( |
|
1015 text, origEncoding, forcedEncoding=forcedEncoding |
|
1016 ) |
|
1017 self.writeFile(filename, data, withBackup=withBackup) |
|
1018 |
|
1019 return encoding |