Debian Codegraph @

dns/rdtypes/ANY/RP.py

raw
1 # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
2
3 # Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
4 #
5 # Permission to use, copy, modify, and distribute this software and its
6 # documentation for any purpose with or without fee is hereby granted,
7 # provided that the above copyright notice and this permission notice
8 # appear in all copies.
9 #
10 # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
16 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
18 import dns.exception
19 import dns.immutable
20 import dns.name
21 import dns.rdata
22
23
24 @dns.immutable.immutable
25 class RP(dns.rdata.Rdata):
26 """RP record"""
27
28 # see: RFC 1183
29
30 __slots__ = ["mbox", "txt"]
31
32 def __init__(self, rdclass, rdtype, mbox, txt):
33 super().__init__(rdclass, rdtype)
34 self.mbox = self._as_name(mbox)
35 self.txt = self._as_name(txt)
36
37 def to_text(self, origin=None, relativize=True, **kw):
38 mbox = self.mbox.choose_relativity(origin, relativize)
39 txt = self.txt.choose_relativity(origin, relativize)
40 return f"{str(mbox)} {str(txt)}"
41
42 @classmethod
43 def from_text(
44 cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None
45 ):
46 mbox = tok.get_name(origin, relativize, relativize_to)
47 txt = tok.get_name(origin, relativize, relativize_to)
48 return cls(rdclass, rdtype, mbox, txt)
49
50 def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
51 self.mbox.to_wire(file, None, origin, canonicalize)
52 self.txt.to_wire(file, None, origin, canonicalize)
53
54 @classmethod
55 def from_wire_parser(cls, rdclass, rdtype, parser, origin=None):
56 mbox = parser.get_name(origin)
57 txt = parser.get_name(origin)
58 return cls(rdclass, rdtype, mbox, txt)