eric6/Plugins/WizardPlugins/QRegularExpressionWizard/QRegularExpressionWizardServer.py

Tue, 10 Sep 2019 19:30:07 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 10 Sep 2019 19:30:07 +0200
changeset 7229
53054eb5b15a
parent 6942
2602857055c5
child 7360
9190402e4505
permissions
-rw-r--r--

Removed obsolete "from __future__ import ..." statements.

2747
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
3 # Copyright (c) 2013 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
2747
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
2748
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
6 """
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
7 Module implementing the PyQt5 server part of the QRegularExpression wizzard.
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
8 """
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
9
2791
a9577f248f04 Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2748
diff changeset
10
2747
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import json
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import sys
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 def rxValidate(regexp, options):
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 """
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 Function to validate the given regular expression.
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 @param regexp regular expression to validate (string)
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 @param options list of options (list of string)
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 @return tuple of flag indicating validity (boolean), error
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 string (string) and error offset (integer)
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 try:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 from PyQt5.QtCore import QRegularExpression
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 rxOptions = QRegularExpression.NoPatternOption
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 if "CaseInsensitiveOption" in options:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 rxOptions |= QRegularExpression.CaseInsensitiveOption
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 if "MultilineOption" in options:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 rxOptions |= QRegularExpression.MultilineOption
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 if "DotMatchesEverythingOption" in options:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 rxOptions |= QRegularExpression.DotMatchesEverythingOption
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 if "ExtendedPatternSyntaxOption" in options:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 rxOptions |= QRegularExpression.ExtendedPatternSyntaxOption
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 if "InvertedGreedinessOption" in options:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 rxOptions |= QRegularExpression.InvertedGreedinessOption
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 if "UseUnicodePropertiesOption" in options:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 rxOptions |= QRegularExpression.UseUnicodePropertiesOption
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 if "DontCaptureOption" in options:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 rxOptions |= QRegularExpression.DontCaptureOption
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 error = ""
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 errorOffset = -1
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 re = QRegularExpression(regexp, rxOptions)
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 valid = re.isValid()
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 if not valid:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 error = re.errorString()
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 errorOffset = re.patternErrorOffset()
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 except ImportError:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 valid = False
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 error = "ImportError"
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 errorOffset = 0
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 return valid, error, errorOffset
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
2748
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
57 def rxExecute(regexp, options, text, startpos):
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
58 """
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
59 Function to execute the given regular expression for a given text.
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
60
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
61 @param regexp regular expression to validate (string)
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
62 @param options list of options (list of string)
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
63 @param text text to execute on (string)
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
64 @param startpos start position for the execution (integer)
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
65 @return tuple of a flag indicating a successful match (boolean) and
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
66 a list of captures containing the complete match as matched string
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
67 (string), match start (integer), match end (integer) and match length
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
68 (integer) for each entry
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
69 """
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
70 valid, error, errorOffset = rxValidate(regexp, options)
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
71 if not valid:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
72 return valid, error, errorOffset
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
73
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
74 from PyQt5.QtCore import QRegularExpression
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
75 rxOptions = QRegularExpression.NoPatternOption
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
76 if "CaseInsensitiveOption" in options:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
77 rxOptions |= QRegularExpression.CaseInsensitiveOption
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
78 if "MultilineOption" in options:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
79 rxOptions |= QRegularExpression.MultilineOption
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
80 if "DotMatchesEverythingOption" in options:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
81 rxOptions |= QRegularExpression.DotMatchesEverythingOption
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
82 if "ExtendedPatternSyntaxOption" in options:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
83 rxOptions |= QRegularExpression.ExtendedPatternSyntaxOption
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
84 if "InvertedGreedinessOption" in options:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
85 rxOptions |= QRegularExpression.InvertedGreedinessOption
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
86 if "UseUnicodePropertiesOption" in options:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
87 rxOptions |= QRegularExpression.UseUnicodePropertiesOption
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
88 if "DontCaptureOption" in options:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
89 rxOptions |= QRegularExpression.DontCaptureOption
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
90
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
91 matched = False
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
92 captures = []
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
93 re = QRegularExpression(regexp, rxOptions)
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
94 match = re.match(text, startpos)
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
95 if match.hasMatch():
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
96 matched = True
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
97 for index in range(match.lastCapturedIndex() + 1):
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
98 captures.append([
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
99 match.captured(index),
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
100 match.capturedStart(index),
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
101 match.capturedEnd(index),
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
102 match.capturedLength(index)
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
103 ])
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
104
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
105 return matched, captures
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
106
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
107
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
108 def main():
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
109 """
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
110 Function containing the main routine.
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
111 """
2747
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 while True:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 commandStr = sys.stdin.readline()
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 try:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 commandDict = json.loads(commandStr)
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 responseDict = {"error": ""}
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 if "command" in commandDict:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 command = commandDict["command"]
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 if command == "exit":
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 break
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 elif command == "available":
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 try:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 import PyQt5 # __IGNORE_WARNING__
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 responseDict["available"] = True
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 except ImportError:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 responseDict["available"] = False
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 elif command == "validate":
3005
3953ddfb991d Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2748
diff changeset
128 valid, error, errorOffset = rxValidate(
3953ddfb991d Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2748
diff changeset
129 commandDict["regexp"], commandDict["options"])
2747
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 responseDict["valid"] = valid
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 responseDict["errorMessage"] = error
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 responseDict["errorOffset"] = errorOffset
2748
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
133 elif command == "execute":
3005
3953ddfb991d Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2748
diff changeset
134 valid, error, errorOffset = rxValidate(
3953ddfb991d Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2748
diff changeset
135 commandDict["regexp"], commandDict["options"])
2748
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
136 if not valid:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
137 responseDict["valid"] = valid
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
138 responseDict["errorMessage"] = error
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
139 responseDict["errorOffset"] = errorOffset
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
140 else:
3025
67064c71df21 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3005
diff changeset
141 matched, captures = rxExecute(
67064c71df21 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3005
diff changeset
142 commandDict["regexp"], commandDict["options"],
67064c71df21 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3005
diff changeset
143 commandDict["text"], commandDict["startpos"])
2748
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
144 responseDict["matched"] = matched
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
145 responseDict["captures"] = captures
2747
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 except ValueError as err:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 responseDict = {"error": str(err)}
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 except Exception as err:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 responseDict = {"error": str(err)}
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 responseStr = json.dumps(responseDict)
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 sys.stdout.write(responseStr)
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 sys.stdout.flush()
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 sys.exit(0)
2748
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
155
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
156
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
157 if __name__ == "__main__":
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
158 main()

eric ide

mercurial