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

Method section_count

dns/message.py:500–526  ·  view source on GitHub ↗

Returns the number of records in the specified section. *section*, an ``int`` section number, a ``str`` section name, or one of the section attributes of this message. This specifies the the section of the message to count. For example:: my_message.section_cou

(self, section: SectionType)

Source from the content-addressed store, hash-verified

498 return rrset
499
500 def section_count(self, section: SectionType) -> int:
501 """Returns the number of records in the specified section.
502
503 *section*, an ``int`` section number, a ``str`` section name, or one of
504 the section attributes of this message. This specifies the
505 the section of the message to count. For example::
506
507 my_message.section_count(my_message.answer)
508 my_message.section_count(dns.message.ANSWER)
509 my_message.section_count("ANSWER")
510 """
511
512 if isinstance(section, int):
513 section_number = section
514 section = self.section_from_number(section_number)
515 elif isinstance(section, str):
516 section_number = self._section_enum.from_text(section)
517 section = self.section_from_number(section_number)
518 else:
519 section_number = self.section_number(section)
520 count = sum(max(1, len(rrs)) for rrs in section)
521 if section_number == MessageSection.ADDITIONAL:
522 if self.opt is not None:
523 count += 1
524 if self.tsig is not None:
525 count += 1
526 return count
527
528 def _compute_opt_reserve(self) -> int:
529 """Compute the size required for the OPT RR, padding excluded"""

Callers 2

test_section_countMethod · 0.80

Calls 3

section_from_numberMethod · 0.95
section_numberMethod · 0.95
from_textMethod · 0.45

Tested by 2

test_section_countMethod · 0.64