--- a/src/eric7/Plugins/WizardPlugins/QRegularExpressionWizard/QRegularExpressionWizardServer.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/Plugins/WizardPlugins/QRegularExpressionWizard/QRegularExpressionWizardServer.py Wed Jul 13 14:55:47 2022 +0200 @@ -14,7 +14,7 @@ def rxValidate(regexp, options): """ Function to validate the given regular expression. - + @param regexp regular expression to validate (string) @param options list of options (list of string) @return tuple of flag indicating validity (boolean), error @@ -22,30 +22,23 @@ """ try: from PyQt6.QtCore import QRegularExpression + rxOptions = QRegularExpression.PatternOption.NoPatternOption if "CaseInsensitiveOption" in options: rxOptions |= QRegularExpression.PatternOption.CaseInsensitiveOption if "MultilineOption" in options: rxOptions |= QRegularExpression.PatternOption.MultilineOption if "DotMatchesEverythingOption" in options: - rxOptions |= ( - QRegularExpression.PatternOption.DotMatchesEverythingOption - ) + rxOptions |= QRegularExpression.PatternOption.DotMatchesEverythingOption if "ExtendedPatternSyntaxOption" in options: - rxOptions |= ( - QRegularExpression.PatternOption.ExtendedPatternSyntaxOption - ) + rxOptions |= QRegularExpression.PatternOption.ExtendedPatternSyntaxOption if "InvertedGreedinessOption" in options: - rxOptions |= ( - QRegularExpression.PatternOption.InvertedGreedinessOption - ) + rxOptions |= QRegularExpression.PatternOption.InvertedGreedinessOption if "UseUnicodePropertiesOption" in options: - rxOptions |= ( - QRegularExpression.PatternOption.UseUnicodePropertiesOption - ) + rxOptions |= QRegularExpression.PatternOption.UseUnicodePropertiesOption if "DontCaptureOption" in options: rxOptions |= QRegularExpression.PatternOption.DontCaptureOption - + error = "" errorOffset = -1 re = QRegularExpression(regexp, rxOptions) @@ -57,14 +50,14 @@ valid = False error = "ImportError" errorOffset = 0 - + return valid, error, errorOffset def rxExecute(regexp, options, text, startpos): """ Function to execute the given regular expression for a given text. - + @param regexp regular expression to validate (string) @param options list of options (list of string) @param text text to execute on (string) @@ -77,30 +70,25 @@ valid, error, errorOffset = rxValidate(regexp, options) if not valid: return valid, error, errorOffset - + from PyQt6.QtCore import QRegularExpression + rxOptions = QRegularExpression.PatternOption.NoPatternOption if "CaseInsensitiveOption" in options: rxOptions |= QRegularExpression.PatternOption.CaseInsensitiveOption if "MultilineOption" in options: rxOptions |= QRegularExpression.PatternOption.MultilineOption if "DotMatchesEverythingOption" in options: - rxOptions |= ( - QRegularExpression.PatternOption.DotMatchesEverythingOption - ) + rxOptions |= QRegularExpression.PatternOption.DotMatchesEverythingOption if "ExtendedPatternSyntaxOption" in options: - rxOptions |= ( - QRegularExpression.PatternOption.ExtendedPatternSyntaxOption - ) + rxOptions |= QRegularExpression.PatternOption.ExtendedPatternSyntaxOption if "InvertedGreedinessOption" in options: rxOptions |= QRegularExpression.PatternOption.InvertedGreedinessOption if "UseUnicodePropertiesOption" in options: - rxOptions |= ( - QRegularExpression.PatternOption.UseUnicodePropertiesOption - ) + rxOptions |= QRegularExpression.PatternOption.UseUnicodePropertiesOption if "DontCaptureOption" in options: rxOptions |= QRegularExpression.PatternOption.DontCaptureOption - + matched = False captures = [] re = QRegularExpression(regexp, rxOptions) @@ -108,13 +96,15 @@ if match.hasMatch(): matched = True for index in range(match.lastCapturedIndex() + 1): - captures.append([ - match.captured(index), - match.capturedStart(index), - match.capturedEnd(index), - match.capturedLength(index) - ]) - + captures.append( + [ + match.captured(index), + match.capturedStart(index), + match.capturedEnd(index), + match.capturedLength(index), + ] + ) + return matched, captures @@ -133,27 +123,33 @@ break elif command == "available": try: - import PyQt6 # __IGNORE_WARNING__ + import PyQt6 # __IGNORE_WARNING__ + responseDict["available"] = True except ImportError: responseDict["available"] = False elif command == "validate": valid, error, errorOffset = rxValidate( - commandDict["regexp"], commandDict["options"]) + commandDict["regexp"], commandDict["options"] + ) responseDict["valid"] = valid responseDict["errorMessage"] = error responseDict["errorOffset"] = errorOffset elif command == "execute": valid, error, errorOffset = rxValidate( - commandDict["regexp"], commandDict["options"]) + commandDict["regexp"], commandDict["options"] + ) if not valid: responseDict["valid"] = valid responseDict["errorMessage"] = error responseDict["errorOffset"] = errorOffset else: matched, captures = rxExecute( - commandDict["regexp"], commandDict["options"], - commandDict["text"], commandDict["startpos"]) + commandDict["regexp"], + commandDict["options"], + commandDict["text"], + commandDict["startpos"], + ) responseDict["matched"] = matched responseDict["captures"] = captures except ValueError as err: @@ -163,7 +159,7 @@ responseStr = json.dumps(responseDict) sys.stdout.write(responseStr) sys.stdout.flush() - + sys.exit(0)