Searches occurrences of value inside expression at 0-depth level regarding the parentheses >>> _ = "SELECT (SELECT id FROM users WHERE 2>1) AS result FROM DUAL"; _[zeroDepthSearch(_, "FROM")[0]:] 'FROM DUAL' >>> _ = "a(b; c),d;e"; _[zeroDepthSearch(_, "[;, ]")[0]:] ',d;e'
(expression, value)
| 5209 | return True |
| 5210 | |
| 5211 | def zeroDepthSearch(expression, value): |
| 5212 | """ |
| 5213 | Searches occurrences of value inside expression at 0-depth level |
| 5214 | regarding the parentheses |
| 5215 | |
| 5216 | >>> _ = "SELECT (SELECT id FROM users WHERE 2>1) AS result FROM DUAL"; _[zeroDepthSearch(_, "FROM")[0]:] |
| 5217 | 'FROM DUAL' |
| 5218 | >>> _ = "a(b; c),d;e"; _[zeroDepthSearch(_, "[;, ]")[0]:] |
| 5219 | ',d;e' |
| 5220 | """ |
| 5221 | |
| 5222 | retVal = [] |
| 5223 | |
| 5224 | depth = 0 |
| 5225 | for index in xrange(len(expression)): |
| 5226 | if expression[index] == '(': |
| 5227 | depth += 1 |
| 5228 | elif expression[index] == ')': |
| 5229 | depth -= 1 |
| 5230 | elif depth == 0: |
| 5231 | if value.startswith('[') and value.endswith(']'): |
| 5232 | if re.search(value, expression[index:index + 1]): |
| 5233 | retVal.append(index) |
| 5234 | elif expression[index:index + len(value)] == value: |
| 5235 | retVal.append(index) |
| 5236 | |
| 5237 | return retVal |
| 5238 | |
| 5239 | def splitFields(fields, delimiter=','): |
| 5240 | """ |
no test coverage detected
searching dependent graphs…