Package dns :: Package rdtypes :: Package ANY :: Module RP
[hide private]
[frames] | no frames]

Source Code for Module dns.rdtypes.ANY.RP

 1  # Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. 
 2  # 
 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. 
 7  # 
 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. 
15   
16  import dns.exception 
17  import dns.rdata 
18  import dns.name 
19  import dns.util 
20   
21 -class RP(dns.rdata.Rdata):
22 """RP record 23 24 @ivar mbox: The responsible person's mailbox 25 @type mbox: dns.name.Name object 26 @ivar txt: The owner name of a node with TXT records, or the root name 27 if no TXT records are associated with this RP. 28 @type txt: dns.name.Name object 29 @see: RFC 1183""" 30 31 __slots__ = ['mbox', 'txt'] 32
33 - def __init__(self, rdclass, rdtype, mbox, txt):
34 super(RP, self).__init__(rdclass, rdtype) 35 self.mbox = mbox 36 self.txt = txt
37
38 - def to_text(self, origin=None, relativize=True, **kw):
39 mbox = self.mbox.choose_relativity(origin, relativize) 40 txt = self.txt.choose_relativity(origin, relativize) 41 return "%s %s" % (str(mbox), str(txt))
42
43 - def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
44 mbox = tok.get_name() 45 txt = tok.get_name() 46 mbox = mbox.choose_relativity(origin, relativize) 47 txt = txt.choose_relativity(origin, relativize) 48 tok.get_eol() 49 return cls(rdclass, rdtype, mbox, txt)
50 51 from_text = classmethod(from_text) 52
53 - def to_wire(self, file, compress = None, origin = None):
54 self.mbox.to_wire(file, None, origin) 55 self.txt.to_wire(file, None, origin)
56
57 - def to_digestable(self, origin = None):
58 return self.mbox.to_digestable(origin) + \ 59 self.txt.to_digestable(origin)
60
61 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
62 (mbox, cused) = dns.name.from_wire(wire[: current + rdlen], 63 current) 64 current += cused 65 rdlen -= cused 66 if rdlen <= 0: 67 raise dns.exception.FormError 68 (txt, cused) = dns.name.from_wire(wire[: current + rdlen], 69 current) 70 if cused != rdlen: 71 raise dns.exception.FormError 72 if not origin is None: 73 mbox = mbox.relativize(origin) 74 txt = txt.relativize(origin) 75 return cls(rdclass, rdtype, mbox, txt)
76 77 from_wire = classmethod(from_wire) 78
79 - def choose_relativity(self, origin = None, relativize = True):
80 self.mbox = self.mbox.choose_relativity(origin, relativize) 81 self.txt = self.txt.choose_relativity(origin, relativize)
82
83 - def _cmp(self, other):
84 v = dns.util.cmp(self.mbox, other.mbox) 85 if v == 0: 86 v = dns.util.cmp(self.txt, other.txt) 87 return v
88