49 |
49 |
50 |
50 |
51 def validateRegExp(regexp): |
51 def validateRegExp(regexp): |
52 """ |
52 """ |
53 Function to validate a given regular expression. |
53 Function to validate a given regular expression. |
54 |
54 |
55 @param regexp regular expression to be validated |
55 @param regexp regular expression to be validated |
56 @type str |
56 @type str |
57 @return tuple containing a flag indicating validity and an error message |
57 @return tuple containing a flag indicating validity and an error message |
58 @rtype tuple of (bool, str) |
58 @rtype tuple of (bool, str) |
59 """ |
59 """ |
63 return True, "" |
63 return True, "" |
64 except re.error as e: |
64 except re.error as e: |
65 return ( |
65 return ( |
66 False, |
66 False, |
67 QCoreApplication.translate( |
67 QCoreApplication.translate( |
68 "BlackUtilities", |
68 "BlackUtilities", "Invalid regular expression: {0}" |
69 "Invalid regular expression: {0}" |
69 ).format(str(e)), |
70 ).format(str(e)) |
|
71 ) |
70 ) |
72 except IndexError: |
71 except IndexError: |
73 return ( |
72 return ( |
74 False, |
73 False, |
75 QCoreApplication.translate( |
74 QCoreApplication.translate( |
76 "BlackUtilities", |
75 "BlackUtilities", "Invalid regular expression: missing group name" |
77 "Invalid regular expression: missing group name" |
76 ), |
78 ) |
|
79 ) |
77 ) |
80 else: |
78 else: |
81 return ( |
79 return ( |
82 False, |
80 False, |
83 QCoreApplication.translate( |
81 QCoreApplication.translate( |
84 "BlackUtilities", |
82 "BlackUtilities", "A regular expression must be given." |
85 "A regular expression must be given." |
83 ), |
86 ) |
|
87 ) |
84 ) |