Plugins/WizardPlugins/QRegularExpressionWizard/QRegularExpressionWizardServer.py

Wed, 08 Jan 2014 19:07:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 08 Jan 2014 19:07:23 +0100
changeset 3186
a05eff845522
parent 3160
209a07d7e401
child 3178
f25fc1364c88
permissions
-rw-r--r--

Changed all the file or directory selection buttons to QToolButton and gave them an icon.

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
3160
209a07d7e401 Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3025
diff changeset
3 # Copyright (c) 2013 - 2014 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
2747
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 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
11 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
12
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 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
15 """
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 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
17
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 @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
19 @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
20 @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
21 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
22 """
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 try:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 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
25 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
26 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
27 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
28 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
29 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
30 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
31 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
32 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
33 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
34 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
35 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
36 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
37 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
38 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
39 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
40
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 error = ""
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 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
43 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
44 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
45 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
46 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
47 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
48 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
49 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
50 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
51 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
52
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 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
54
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
2748
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
56 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
57 """
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
58 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
59
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
60 @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
61 @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
62 @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
63 @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
64 @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
65 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
66 (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
67 (integer) for each entry
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
68 """
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
69 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
70 if not valid:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
71 return valid, error, errorOffset
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
72
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
73 from PyQt5.QtCore import QRegularExpression
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
74 rxOptions = QRegularExpression.NoPatternOption
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
75 if "CaseInsensitiveOption" in options:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
76 rxOptions |= QRegularExpression.CaseInsensitiveOption
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
77 if "MultilineOption" in options:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
78 rxOptions |= QRegularExpression.MultilineOption
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
79 if "DotMatchesEverythingOption" in options:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
80 rxOptions |= QRegularExpression.DotMatchesEverythingOption
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
81 if "ExtendedPatternSyntaxOption" in options:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
82 rxOptions |= QRegularExpression.ExtendedPatternSyntaxOption
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
83 if "InvertedGreedinessOption" in options:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
84 rxOptions |= QRegularExpression.InvertedGreedinessOption
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
85 if "UseUnicodePropertiesOption" in options:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
86 rxOptions |= QRegularExpression.UseUnicodePropertiesOption
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
87 if "DontCaptureOption" in options:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
88 rxOptions |= QRegularExpression.DontCaptureOption
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
89
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
90 matched = False
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
91 captures = []
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
92 re = QRegularExpression(regexp, rxOptions)
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
93 match = re.match(text, startpos)
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
94 if match.hasMatch():
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
95 matched = True
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
96 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
97 captures.append([
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
98 match.captured(index),
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
99 match.capturedStart(index),
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
100 match.capturedEnd(index),
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
101 match.capturedLength(index)
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
102 ])
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 return matched, captures
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
105
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 def main():
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
108 """
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
109 Function containing the main routine.
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
110 """
2747
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 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
112 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
113 try:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 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
115 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
116 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
117 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
118 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
119 break
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 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
121 try:
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131 responseDict["errorOffset"] = errorOffset
2748
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
132 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
133 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
134 commandDict["regexp"], commandDict["options"])
2748
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
135 if not valid:
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
136 responseDict["valid"] = valid
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
137 responseDict["errorMessage"] = error
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
138 responseDict["errorOffset"] = errorOffset
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
139 else:
3025
67064c71df21 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3005
diff changeset
140 matched, captures = rxExecute(
67064c71df21 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3005
diff changeset
141 commandDict["regexp"], commandDict["options"],
67064c71df21 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3005
diff changeset
142 commandDict["text"], commandDict["startpos"])
2748
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
143 responseDict["matched"] = matched
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
144 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
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152
68b920f307ff Started to rework the QRegularExpression wizard because PyQt4 and PyQt5 cannot be mixed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 sys.exit(0)
2748
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
154
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 if __name__ == "__main__":
3731148a7cdf Completed the coding stuff of the QRegularExpression support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2747
diff changeset
157 main()

eric ide

mercurial