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

Class Tokenizer

dns/tokenizer.py:198–706  ·  view source on GitHub ↗

A DNS zone file format tokenizer. A token object is basically a (type, value) tuple. The valid types are EOF, EOL, WHITESPACE, IDENTIFIER, QUOTED_STRING, COMMENT, and DELIMITER. file: The file to tokenize ungotten_char: The most recently ungotten character, or None. ungo

Source from the content-addressed store, hash-verified

196
197
198class Tokenizer:
199 """A DNS zone file format tokenizer.
200
201 A token object is basically a (type, value) tuple. The valid
202 types are EOF, EOL, WHITESPACE, IDENTIFIER, QUOTED_STRING,
203 COMMENT, and DELIMITER.
204
205 file: The file to tokenize
206
207 ungotten_char: The most recently ungotten character, or None.
208
209 ungotten_token: The most recently ungotten token, or None.
210
211 multiline: The current multiline level. This value is increased
212 by one every time a '(' delimiter is read, and decreased by one every time
213 a ')' delimiter is read.
214
215 quoting: This variable is true if the tokenizer is currently
216 reading a quoted string.
217
218 eof: This variable is true if the tokenizer has encountered EOF.
219
220 delimiters: The current delimiter dictionary.
221
222 line_number: The current line number
223
224 filename: A filename that will be returned by the where() method.
225
226 idna_codec: A dns.name.IDNACodec, specifies the IDNA
227 encoder/decoder. If None, the default IDNA 2003
228 encoder/decoder is used.
229 """
230
231 def __init__(
232 self,
233 f: Any = sys.stdin,
234 filename: str | None = None,
235 idna_codec: dns.name.IDNACodec | None = None,
236 ):
237 """Initialize a tokenizer instance.
238
239 f: The file to tokenize. The default is sys.stdin.
240 This parameter may also be a string, in which case the tokenizer
241 will take its input from the contents of the string.
242
243 filename: the name of the filename that the where() method
244 will return.
245
246 idna_codec: A dns.name.IDNACodec, specifies the IDNA
247 encoder/decoder. If None, the default IDNA 2003
248 encoder/decoder is used.
249 """
250
251 if isinstance(f, str):
252 f = io.StringIO(f)
253 if filename is None:
254 filename = "<string>"
255 elif isinstance(f, bytes):

Callers 1

Calls

no outgoing calls

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…