MCPcopy Create free account
hub / github.com/rthalley/dnspython / Token

Class Token

dns/tokenizer.py:44–195  ·  view source on GitHub ↗

A DNS zone file format token. ttype: The token type value: The token value has_escape: Does the token value contain escapes?

Source from the content-addressed store, hash-verified

42
43
44class 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}"'

Callers 12

unescapeMethod · 0.85
unescape_to_bytesMethod · 0.85
getMethod · 0.85
testStrMethod · 0.85
testQuotedString1Method · 0.85
testQuotedString2Method · 0.85
testQuotedString3Method · 0.85
testQuotedString4Method · 0.85
testComment2Method · 0.85
testComment3Method · 0.85
testMultiline1Method · 0.85
testMultiline2Method · 0.85

Calls

no outgoing calls

Tested by 9

testStrMethod · 0.68
testQuotedString1Method · 0.68
testQuotedString2Method · 0.68
testQuotedString3Method · 0.68
testQuotedString4Method · 0.68
testComment2Method · 0.68
testComment3Method · 0.68
testMultiline1Method · 0.68
testMultiline2Method · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…