Read the next token and interpret it as a string. Raises dns.exception.SyntaxError if not a string. Raises dns.exception.SyntaxError if token value length exceeds max_length (if specified). Returns a string.
(self, max_length: int | None = None)
| 567 | return value |
| 568 | |
| 569 | def get_string(self, max_length: int | None = None) -> str: |
| 570 | """Read the next token and interpret it as a string. |
| 571 | |
| 572 | Raises dns.exception.SyntaxError if not a string. |
| 573 | Raises dns.exception.SyntaxError if token value length |
| 574 | exceeds max_length (if specified). |
| 575 | |
| 576 | Returns a string. |
| 577 | """ |
| 578 | |
| 579 | token = self.get().unescape() |
| 580 | if not (token.is_identifier() or token.is_quoted_string()): |
| 581 | raise dns.exception.SyntaxError("expecting a string") |
| 582 | if max_length and len(token.value) > max_length: |
| 583 | raise dns.exception.SyntaxError("string too long") |
| 584 | return token.value |
| 585 | |
| 586 | def get_identifier(self) -> str: |
| 587 | """Read the next token, which should be an identifier. |