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

Method get

dns/tokenizer.py:342–451  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 15

from_textFunction · 0.95
nextMethod · 0.95
get_intMethod · 0.95
get_stringMethod · 0.95
get_identifierMethod · 0.95
get_remainingMethod · 0.95
get_nameMethod · 0.95
get_eol_as_tokenMethod · 0.95
get_ttlMethod · 0.95
testStrMethod · 0.95

Calls 6

skip_whitespaceMethod · 0.95
_get_charMethod · 0.95
_unget_charMethod · 0.95
TokenClass · 0.85
is_whitespaceMethod · 0.80
is_commentMethod · 0.80

Tested by 15

testStrMethod · 0.76
testQuotedString1Method · 0.76
testQuotedString2Method · 0.76
testQuotedString3Method · 0.76
testQuotedString4Method · 0.76
testQuotedString5Method · 0.76
testQuotedString6Method · 0.76
testQuotedString7Method · 0.76
testEmpty1Method · 0.76
testEmpty2Method · 0.76
testEOLMethod · 0.76