| 228 | return self.width |
| 229 | |
| 230 | class Tokenizer: |
| 231 | def __init__(self, string): |
| 232 | self.istext = isinstance(string, str) |
| 233 | self.string = string |
| 234 | if not self.istext: |
| 235 | string = str(string, 'latin1') |
| 236 | self.decoded_string = string |
| 237 | self.index = 0 |
| 238 | self.next = None |
| 239 | self.__next() |
| 240 | def __next(self): |
| 241 | index = self.index |
| 242 | try: |
| 243 | char = self.decoded_string[index] |
| 244 | except IndexError: |
| 245 | self.next = None |
| 246 | return |
| 247 | if char == "\\": |
| 248 | index += 1 |
| 249 | try: |
| 250 | char += self.decoded_string[index] |
| 251 | except IndexError: |
| 252 | raise error("bad escape (end of pattern)", |
| 253 | self.string, len(self.string) - 1) from None |
| 254 | self.index = index + 1 |
| 255 | self.next = char |
| 256 | def match(self, char): |
| 257 | if char == self.next: |
| 258 | self.__next() |
| 259 | return True |
| 260 | return False |
| 261 | def get(self): |
| 262 | this = self.next |
| 263 | self.__next() |
| 264 | return this |
| 265 | def getwhile(self, n, charset): |
| 266 | result = '' |
| 267 | for _ in range(n): |
| 268 | c = self.next |
| 269 | if c not in charset: |
| 270 | break |
| 271 | result += c |
| 272 | self.__next() |
| 273 | return result |
| 274 | def getuntil(self, terminator, name): |
| 275 | result = '' |
| 276 | while True: |
| 277 | c = self.next |
| 278 | self.__next() |
| 279 | if c is None: |
| 280 | if not result: |
| 281 | raise self.error("missing " + name) |
| 282 | raise self.error("missing %s, unterminated name" % terminator, |
| 283 | len(result)) |
| 284 | if c == terminator: |
| 285 | if not result: |
| 286 | raise self.error("missing " + name, 1) |
| 287 | break |
no outgoing calls
no test coverage detected
searching dependent graphs…