diff -r 2b015db9761a -r ba20efe10336 src/eric7/Utilities/__init__.py --- a/src/eric7/Utilities/__init__.py Sun Jun 02 09:51:47 2024 +0200 +++ b/src/eric7/Utilities/__init__.py Wed Jul 03 09:20:41 2024 +0200 @@ -36,7 +36,7 @@ from eric7 import Preferences from eric7.__version__ import Version from eric7.EricWidgets.EricApplication import ericApp -from eric7.SystemUtilities import DesktopUtilities, OSUtilities +from eric7.SystemUtilities import DesktopUtilities, FileSystemUtilities, OSUtilities from eric7.UI.Info import Program @@ -339,6 +339,32 @@ return str(text, "utf-8", "ignore"), "utf-8-ignore" +def decodeWithEncoding(text, encoding): + """ + Function to decode some byte text into a string. + + @param text byte text to decode + @type bytes + @param encoding encoding to be used to read the file + @type str + @return tuple of decoded text and encoding + @rtype tuple of (str, str) + """ + if encoding: + with contextlib.suppress(UnicodeError, LookupError): + return str(text, encoding), "{0}-selected".format(encoding) + + # Try default encoding + with contextlib.suppress(UnicodeError, LookupError): + codec = Preferences.getEditor("DefaultEncoding") + return str(text, codec), "{0}-default".format(codec) + + # Assume UTF-8 loosing information + return str(text, "utf-8", "ignore"), "utf-8-ignore" + else: + return decode(text) + + def readEncodedFileWithEncoding(filename, encoding): """ Function to read a file and decode its contents into proper text. @@ -352,19 +378,7 @@ """ with open(filename, "rb") as f: text = f.read() - if encoding: - with contextlib.suppress(UnicodeError, LookupError): - return str(text, encoding), "{0}-selected".format(encoding) - - # Try default encoding - with contextlib.suppress(UnicodeError, LookupError): - codec = Preferences.getEditor("DefaultEncoding") - return str(text, codec), "{0}-default".format(codec) - - # Assume UTF-8 loosing information - return str(text, "utf-8", "ignore"), "utf-8-ignore" - else: - return decode(text) + return decodeWithEncoding(text, encoding) def writeEncodedFile(filename, text, origEncoding, forcedEncoding=""): @@ -890,6 +904,16 @@ basename = os.path.splitext(fn)[0] filename = "{0}.coverage".format(basename) if mustExist: + if FileSystemUtilities.isRemoteFileName(fn): + ericServer = ericApp().getObject("EricServer") + if ericServer.isServerConnected() and ericServer.getServiceInterface( + "FileSystem" + ).exists(filename): + return filename + else: + return "" + + # It is a local file. if os.path.isfile(filename): return filename else: @@ -930,12 +954,22 @@ basename = os.path.splitext(fn)[0] filename = "{0}.profile".format(basename) if mustExist: + if FileSystemUtilities.isRemoteFileName(fn): + ericServer = ericApp().getObject("EricServer") + if ericServer.isServerConnected() and ericServer.getServiceInterface( + "FileSystem" + ).exists(filename): + return filename + else: + return "" + + # It is a local file. if os.path.isfile(filename): return filename else: return "" - else: - return filename + + return filename def parseOptionString(s):