1 # Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc.
3 # Permission to use, copy, modify, and distribute this software and its
4 # documentation for any purpose with or without fee is hereby granted,
5 # provided that the above copyright notice and this permission notice
6 # appear in all copies.
8 # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
9 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
11 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
14 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 class RP(dns.rdata.Rdata):
23 @ivar mbox: The responsible person's mailbox
24 @type mbox: dns.name.Name object
25 @ivar txt: The owner name of a node with TXT records, or the root name
26 if no TXT records are associated with this RP.
27 @type txt: dns.name.Name object
30 __slots__ = ['mbox', 'txt']
32 def __init__(self, rdclass, rdtype, mbox, txt):
33 super(RP, self).__init__(rdclass, rdtype)
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 "%s %s" % (str(mbox), str(txt))
42 def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
45 mbox = mbox.choose_relativity(origin, relativize)
46 txt = txt.choose_relativity(origin, relativize)
48 return cls(rdclass, rdtype, mbox, txt)
50 from_text = classmethod(from_text)
52 def to_wire(self, file, compress = None, origin = None):
53 self.mbox.to_wire(file, None, origin)
54 self.txt.to_wire(file, None, origin)
56 def to_digestable(self, origin = None):
57 return self.mbox.to_digestable(origin) + \
58 self.txt.to_digestable(origin)
60 def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
61 (mbox, cused) = dns.name.from_wire(wire[: current + rdlen],
66 raise dns.exception.FormError
67 (txt, cused) = dns.name.from_wire(wire[: current + rdlen],
70 raise dns.exception.FormError
71 if not origin is None:
72 mbox = mbox.relativize(origin)
73 txt = txt.relativize(origin)
74 return cls(rdclass, rdtype, mbox, txt)
76 from_wire = classmethod(from_wire)
78 def choose_relativity(self, origin = None, relativize = True):
79 self.mbox = self.mbox.choose_relativity(origin, relativize)
80 self.txt = self.txt.choose_relativity(origin, relativize)
82 def _cmp(self, other):
83 v = cmp(self.mbox, other.mbox)
85 v = cmp(self.txt, other.txt)