(self, request)
| 192 | return tokens |
| 193 | |
| 194 | def _prepareRequestRegex(self, request): |
| 195 | roundLvl = 0 |
| 196 | squareLvl = 0 |
| 197 | nextEscaped = False |
| 198 | tokens = [] |
| 199 | currentToken = '' |
| 200 | |
| 201 | def verifyErrors(): |
| 202 | if squareLvl not in (0, 1): |
| 203 | raise RegexTokenizationError('Square braces level is {}'.format(squareLvl)) |
| 204 | if roundLvl < 0: |
| 205 | raise RegexTokenizationError('Round braces level is {}'.format(roundLvl)) |
| 206 | |
| 207 | try: |
| 208 | for char in request: |
| 209 | thisEscaped = nextEscaped |
| 210 | nextEscaped = False |
| 211 | if thisEscaped: |
| 212 | currentToken += char |
| 213 | elif char == '\\': |
| 214 | currentToken += char |
| 215 | nextEscaped = True |
| 216 | elif char == '[': |
| 217 | currentToken += char |
| 218 | squareLvl += 1 |
| 219 | elif char == ']': |
| 220 | currentToken += char |
| 221 | squareLvl -= 1 |
| 222 | elif char == '(' and squareLvl == 0: |
| 223 | currentToken += char |
| 224 | roundLvl += 1 |
| 225 | elif char == ')' and squareLvl == 0: |
| 226 | currentToken += char |
| 227 | roundLvl -= 1 |
| 228 | elif char.isspace() and roundLvl == squareLvl == 0: |
| 229 | if currentToken: |
| 230 | tokens.append(currentToken) |
| 231 | currentToken = '' |
| 232 | else: |
| 233 | currentToken += char |
| 234 | verifyErrors() |
| 235 | else: |
| 236 | if currentToken: |
| 237 | tokens.append(currentToken) |
| 238 | # Treat request as normal string if regex tokenization fails |
| 239 | except RegexTokenizationError: |
| 240 | tokens = self._prepareRequestNormal(request) |
| 241 | return tokens |
| 242 | |
| 243 | |
| 244 | class Market: |
no test coverage detected