Get the next token. want_leading: If True, return a WHITESPACE token if the first character read is whitespace. The default is False. want_comment: If True, return a COMMENT token if the first token read is a comment. The default is False. Raises dns.exce
(self, want_leading: bool = False, want_comment: bool = False)
| 340 | skipped += 1 |
| 341 | |
| 342 | def get(self, want_leading: bool = False, want_comment: bool = False) -> Token: |
| 343 | """Get the next token. |
| 344 | |
| 345 | want_leading: If True, return a WHITESPACE token if the |
| 346 | first character read is whitespace. The default is False. |
| 347 | |
| 348 | want_comment: If True, return a COMMENT token if the |
| 349 | first token read is a comment. The default is False. |
| 350 | |
| 351 | Raises dns.exception.UnexpectedEnd: input ended prematurely |
| 352 | |
| 353 | Raises dns.exception.SyntaxError: input was badly formed |
| 354 | |
| 355 | Returns a Token. |
| 356 | """ |
| 357 | |
| 358 | if self.ungotten_token is not None: |
| 359 | utoken = self.ungotten_token |
| 360 | self.ungotten_token = None |
| 361 | if utoken.is_whitespace(): |
| 362 | if want_leading: |
| 363 | return utoken |
| 364 | elif utoken.is_comment(): |
| 365 | if want_comment: |
| 366 | return utoken |
| 367 | else: |
| 368 | return utoken |
| 369 | skipped = self.skip_whitespace() |
| 370 | if want_leading and skipped > 0: |
| 371 | return Token(WHITESPACE, " ") |
| 372 | token = "" |
| 373 | ttype = IDENTIFIER |
| 374 | has_escape = False |
| 375 | while True: |
| 376 | c = self._get_char() |
| 377 | if c == "" or c in self.delimiters: |
| 378 | if c == "" and self.quoting: |
| 379 | raise dns.exception.UnexpectedEnd |
| 380 | if token == "" and ttype != QUOTED_STRING: |
| 381 | if c == "(": |
| 382 | self.multiline += 1 |
| 383 | self.skip_whitespace() |
| 384 | continue |
| 385 | elif c == ")": |
| 386 | if self.multiline <= 0: |
| 387 | raise dns.exception.SyntaxError |
| 388 | self.multiline -= 1 |
| 389 | self.skip_whitespace() |
| 390 | continue |
| 391 | elif c == '"': |
| 392 | if not self.quoting: |
| 393 | self.quoting = True |
| 394 | self.delimiters = _QUOTING_DELIMITERS |
| 395 | ttype = QUOTED_STRING |
| 396 | continue |
| 397 | else: |
| 398 | self.quoting = False |
| 399 | self.delimiters = _DELIMITERS |