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

Method to_text

dns/message.py:212–251  ·  view source on GitHub ↗

Convert the message to text. The *origin*, *relativize*, and any other keyword arguments are passed to the RRset ``to_wire()`` method. Returns a ``str``.

(
        self,
        origin: dns.name.Name | None = None,
        relativize: bool = True,
        **kw: Dict[str, Any],
    )

Source from the content-addressed store, hash-verified

210 return self.to_text()
211
212 def to_text(
213 self,
214 origin: dns.name.Name | None = None,
215 relativize: bool = True,
216 **kw: Dict[str, Any],
217 ) -> str:
218 """Convert the message to text.
219
220 The *origin*, *relativize*, and any other keyword
221 arguments are passed to the RRset ``to_wire()`` method.
222
223 Returns a ``str``.
224 """
225
226 s = io.StringIO()
227 s.write(f"id {self.id}\n")
228 s.write(f"opcode {dns.opcode.to_text(self.opcode())}\n")
229 s.write(f"rcode {dns.rcode.to_text(self.rcode())}\n")
230 s.write(f"flags {dns.flags.to_text(self.flags)}\n")
231 if self.edns >= 0:
232 s.write(f"edns {self.edns}\n")
233 if self.ednsflags != 0:
234 s.write(f"eflags {dns.flags.edns_to_text(self.ednsflags)}\n")
235 s.write(f"payload {self.payload}\n")
236 for opt in self.options:
237 s.write(f"option {opt.to_text()}\n")
238 for name, which in self._section_enum.__members__.items():
239 s.write(f";{name}\n")
240 for rrset in self.section_from_number(which):
241 s.write(rrset.to_text(origin, relativize, **kw))
242 s.write("\n")
243 if self.tsig is not None:
244 s.write(self.tsig.to_text(origin, relativize, **kw))
245 s.write("\n")
246 #
247 # We strip off the final \n so the caller can print the result without
248 # doing weird things to get around eccentricities in Python print
249 # formatting
250 #
251 return s.getvalue()[:-1]
252
253 def __eq__(self, other):
254 """Two messages are equal if they have the same content in the

Callers 1

__str__Method · 0.95

Calls 5

opcodeMethod · 0.95
rcodeMethod · 0.95
section_from_numberMethod · 0.95
writeMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected