A DNS zone file format token. ttype: The token type value: The token value has_escape: Does the token value contain escapes?
| 42 | |
| 43 | |
| 44 | class Token: |
| 45 | """A DNS zone file format token. |
| 46 | |
| 47 | ttype: The token type |
| 48 | value: The token value |
| 49 | has_escape: Does the token value contain escapes? |
| 50 | """ |
| 51 | |
| 52 | def __init__( |
| 53 | self, |
| 54 | ttype: int, |
| 55 | value: Any = "", |
| 56 | has_escape: bool = False, |
| 57 | comment: str | None = None, |
| 58 | ): |
| 59 | """Initialize a token instance.""" |
| 60 | |
| 61 | self.ttype = ttype |
| 62 | self.value = value |
| 63 | self.has_escape = has_escape |
| 64 | self.comment = comment |
| 65 | |
| 66 | def is_eof(self) -> bool: |
| 67 | return self.ttype == EOF |
| 68 | |
| 69 | def is_eol(self) -> bool: |
| 70 | return self.ttype == EOL |
| 71 | |
| 72 | def is_whitespace(self) -> bool: |
| 73 | return self.ttype == WHITESPACE |
| 74 | |
| 75 | def is_identifier(self) -> bool: |
| 76 | return self.ttype == IDENTIFIER |
| 77 | |
| 78 | def is_quoted_string(self) -> bool: |
| 79 | return self.ttype == QUOTED_STRING |
| 80 | |
| 81 | def is_comment(self) -> bool: |
| 82 | return self.ttype == COMMENT |
| 83 | |
| 84 | def is_delimiter(self) -> bool: # pragma: no cover (we don't return delimiters yet) |
| 85 | return self.ttype == DELIMITER |
| 86 | |
| 87 | def is_eol_or_eof(self) -> bool: |
| 88 | return self.ttype == EOL or self.ttype == EOF |
| 89 | |
| 90 | def __eq__(self, other): |
| 91 | if not isinstance(other, Token): |
| 92 | return False |
| 93 | return self.ttype == other.ttype and self.value == other.value |
| 94 | |
| 95 | def __ne__(self, other): |
| 96 | if not isinstance(other, Token): |
| 97 | return True |
| 98 | return self.ttype != other.ttype or self.value != other.value |
| 99 | |
| 100 | def __str__(self): |
| 101 | return f'{self.ttype} "{self.value}"' |
no outgoing calls
searching dependent graphs…