src/eric7/Utilities/__init__.py

branch
eric7-maintenance
changeset 10079
0222a480e93d
parent 9940
a57c188857e9
parent 10069
435cc5875135
child 10349
df7edc29cbfb
equal deleted inserted replaced
10005:097199aec4bd 10079:0222a480e93d
36 from eric7.EricWidgets.EricApplication import ericApp 36 from eric7.EricWidgets.EricApplication import ericApp
37 from eric7.SystemUtilities import DesktopUtilities, OSUtilities 37 from eric7.SystemUtilities import DesktopUtilities, OSUtilities
38 from eric7.UI.Info import Program, Version 38 from eric7.UI.Info import Program, Version
39 39
40 40
41 def __showwarning(message, category, filename, lineno, file=None, line=""): 41 def __showwarning(
42 message, category, filename, lineno, file=None, line="" # noqa: U100
43 ):
42 """ 44 """
43 Module function to raise a SyntaxError for a SyntaxWarning. 45 Module function to raise a SyntaxError for a SyntaxWarning.
44 46
45 @param message warning object 47 @param message warning object
46 @param category type object of the warning 48 @param category type object of the warning
56 err.lineno = lineno 58 err.lineno = lineno
57 raise err 59 raise err
58 60
59 61
60 warnings.showwarning = __showwarning 62 warnings.showwarning = __showwarning
61
62 configDir = None
63 63
64 codingBytes_regexps = [ 64 codingBytes_regexps = [
65 (5, re.compile(rb"""coding[:=]\s*([-\w_.]+)""")), 65 (5, re.compile(rb"""coding[:=]\s*([-\w_.]+)""")),
66 (1, re.compile(rb"""<\?xml.*\bencoding\s*=\s*['"]([-\w_.]+)['"]\?>""")), 66 (1, re.compile(rb"""<\?xml.*\bencoding\s*=\s*['"]([-\w_.]+)['"]\?>""")),
67 ] 67 ]
68 coding_regexps = [ 68 coding_regexps = [
69 (5, re.compile(r"""coding[:=]\s*([-\w_.]+)""")), 69 (5, re.compile(r"""coding[:=]\s*([-\w_.]+)""")),
70 (1, re.compile(r"""<\?xml.*\bencoding\s*=\s*['"]([-\w_.]+)['"]\?>""")), 70 (1, re.compile(r"""<\?xml.*\bencoding\s*=\s*['"]([-\w_.]+)['"]\?>""")),
71 ] 71 ]
72 72
73 supportedCodecs = [ 73 supportedCodecs = [ # noqa: U200
74 "utf-8", 74 "utf-8",
75 "iso-8859-1", 75 "iso-8859-1",
76 "iso-8859-2", 76 "iso-8859-2",
77 "iso-8859-3", 77 "iso-8859-3",
78 "iso-8859-4", 78 "iso-8859-4",
293 try: 293 try:
294 guess = chardet.detect(text) 294 guess = chardet.detect(text)
295 if guess and guess["confidence"] > 0.95 and guess["encoding"] is not None: 295 if guess and guess["confidence"] > 0.95 and guess["encoding"] is not None:
296 codec = guess["encoding"].lower() 296 codec = guess["encoding"].lower()
297 return str(text, codec), "{0}-guessed".format(codec) 297 return str(text, codec), "{0}-guessed".format(codec)
298 except (UnicodeError, LookupError): 298 except (LookupError, UnicodeError):
299 pass 299 pass
300 except ImportError: 300 except ImportError:
301 pass 301 pass
302 302
303 # Try default encoding 303 # Try default encoding
390 # Try declared coding spec 390 # Try declared coding spec
391 coding = get_coding(text) 391 coding = get_coding(text)
392 if coding: 392 if coding:
393 try: 393 try:
394 etext, encoding = text.encode(coding), coding 394 etext, encoding = text.encode(coding), coding
395 except (UnicodeError, LookupError): 395 except (LookupError, UnicodeError):
396 # Error: Declared encoding is incorrect 396 # Error: Declared encoding is incorrect
397 raise CodingError(coding) 397 raise CodingError(coding)
398 else: 398 else:
399 if forcedEncoding: 399 if forcedEncoding:
400 with contextlib.suppress(UnicodeError, LookupError): 400 with contextlib.suppress(UnicodeError, LookupError):
481 try: 481 try:
482 guess = chardet.detect(buffer) 482 guess = chardet.detect(buffer)
483 if guess and guess["encoding"] is not None: 483 if guess and guess["encoding"] is not None:
484 codec = guess["encoding"].lower() 484 codec = guess["encoding"].lower()
485 return str(buffer, encoding=codec) 485 return str(buffer, encoding=codec)
486 except (UnicodeError, LookupError): 486 except (LookupError, UnicodeError):
487 pass 487 pass
488 except ImportError: 488 except ImportError:
489 pass 489 pass
490 490
491 return str(buffer, encoding="utf-8", errors="ignore") 491 return str(buffer, encoding="utf-8", errors="ignore")
625 @param eol new eol setting (string) 625 @param eol new eol setting (string)
626 @return text with converted eols (string) 626 @return text with converted eols (string)
627 """ 627 """
628 if eol == "\r\n": 628 if eol == "\r\n":
629 regexp = re.compile(r"""(\r(?!\n)|(?<!\r)\n)""") 629 regexp = re.compile(r"""(\r(?!\n)|(?<!\r)\n)""")
630 return regexp.sub(lambda m, eol="\r\n": eol, text) 630 return regexp.sub("\r\n", text)
631 elif eol == "\n": 631 elif eol == "\n":
632 regexp = re.compile(r"""(\r\n|\r)""") 632 regexp = re.compile(r"""(\r\n|\r)""")
633 return regexp.sub(lambda m, eol="\n": eol, text) 633 return regexp.sub("\n", text)
634 elif eol == "\r": 634 elif eol == "\r":
635 regexp = re.compile(r"""(\r\n|\n)""") 635 regexp = re.compile(r"""(\r\n|\n)""")
636 return regexp.sub(lambda m, eol="\r": eol, text) 636 return regexp.sub("\r", text)
637 else: 637 else:
638 return text 638 return text
639 639
640 640
641 def linesep(): 641 def linesep():
715 @param filename name of the file to be scanned (string) 715 @param filename name of the file to be scanned (string)
716 @return dictionary of string, boolean, complex, float and int 716 @return dictionary of string, boolean, complex, float and int
717 """ 717 """
718 try: 718 try:
719 source, encoding = readEncodedFile(filename) 719 source, encoding = readEncodedFile(filename)
720 except (UnicodeError, OSError): 720 except (OSError, UnicodeError):
721 return {} 721 return {}
722 722
723 return extractFlags(source) 723 return extractFlags(source)
724 724
725 725
1056 info.append(" PyQt6 {0}".format(PYQT_VERSION_STR)) 1056 info.append(" PyQt6 {0}".format(PYQT_VERSION_STR))
1057 try: 1057 try:
1058 from PyQt6 import QtCharts # __IGNORE_WARNING_I10__ 1058 from PyQt6 import QtCharts # __IGNORE_WARNING_I10__
1059 1059
1060 info.append(" PyQt6-Charts {0}".format(QtCharts.PYQT_CHART_VERSION_STR)) 1060 info.append(" PyQt6-Charts {0}".format(QtCharts.PYQT_CHART_VERSION_STR))
1061 except (ImportError, AttributeError): 1061 except (AttributeError, ImportError):
1062 info.append(" PyQt6-Charts not installed") 1062 info.append(" PyQt6-Charts not installed")
1063 try: 1063 try:
1064 from PyQt6 import QtWebEngineCore # __IGNORE_WARNING_I10__ 1064 from PyQt6 import QtWebEngineCore # __IGNORE_WARNING_I10__
1065 1065
1066 info.append( 1066 info.append(
1067 " PyQt6-WebEngine {0}".format(QtWebEngineCore.PYQT_WEBENGINE_VERSION_STR) 1067 " PyQt6-WebEngine {0}".format(QtWebEngineCore.PYQT_WEBENGINE_VERSION_STR)
1068 ) 1068 )
1069 except (ImportError, AttributeError): 1069 except (AttributeError, ImportError):
1070 info.append(" PyQt6-WebEngine not installed") 1070 info.append(" PyQt6-WebEngine not installed")
1071 info.append(" PyQt6-QScintilla {0}".format(QSCINTILLA_VERSION_STR)) 1071 info.append(" PyQt6-QScintilla {0}".format(QSCINTILLA_VERSION_STR))
1072 info.append(" sip {0}".format(sip_version_str)) 1072 info.append(" sip {0}".format(sip_version_str))
1073 with contextlib.suppress(ImportError): 1073 with contextlib.suppress(ImportError):
1074 from PyQt6 import QtWebEngineWidgets # __IGNORE_WARNING__ 1074 from PyQt6 import QtWebEngineWidgets # __IGNORE_WARNING__

eric ide

mercurial