Plugins/WizardPlugins/QRegularExpressionWizard/QRegularExpressionWizardServer.py

Sat, 14 Dec 2013 23:44:25 +0100

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Sat, 14 Dec 2013 23:44:25 +0100
branch
Py2 comp.
changeset 3145
a9de05d4a22f
parent 3058
0a02c433f52d
child 3161
06f57a834adf
permissions
-rw-r--r--

# __IGNORE_WARNING__ added/ removed.

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

eric ide

mercurial