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

Source Code for Module dns.rdtypes.nsbase

 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  """NS-like base classes.""" 
17   
18  import io 
19   
20  import dns.exception 
21  import dns.rdata 
22  import dns.name 
23  import dns.util 
24 25 -class NSBase(dns.rdata.Rdata):
26 """Base class for rdata that is like an NS record. 27 28 @ivar target: the target name of the rdata 29 @type target: dns.name.Name object""" 30 31 __slots__ = ['target'] 32
33 - def __init__(self, rdclass, rdtype, target):
34 super(NSBase, self).__init__(rdclass, rdtype) 35 self.target = target
36
37 - def to_text(self, origin=None, relativize=True, **kw):
38 target = self.target.choose_relativity(origin, relativize) 39 return str(target)
40 41 @classmethod
42 - def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
43 target = tok.get_name() 44 target = target.choose_relativity(origin, relativize) 45 tok.get_eol() 46 return cls(rdclass, rdtype, target)
47
48 - def to_wire(self, file, compress = None, origin = None):
49 self.target.to_wire(file, compress, origin)
50
51 - def to_digestable(self, origin = None):
52 return self.target.to_digestable(origin)
53 54 @classmethod
55 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
56 (target, cused) = dns.name.from_wire(wire[: current + rdlen], 57 current) 58 if cused != rdlen: 59 raise dns.exception.FormError 60 if not origin is None: 61 target = target.relativize(origin) 62 return cls(rdclass, rdtype, target)
63
64 - def choose_relativity(self, origin = None, relativize = True):
65 self.target = self.target.choose_relativity(origin, relativize)
66
67 - def _cmp(self, other):
68 return dns.util.cmp(self.target, other.target)
69
70 -class UncompressedNS(NSBase):
71 """Base class for rdata that is like an NS record, but whose name 72 is not compressed when convert to DNS wire format, and whose 73 digestable form is not downcased.""" 74
75 - def to_wire(self, file, compress = None, origin = None):
76 super(UncompressedNS, self).to_wire(file, None, origin)
77
78 - def to_digestable(self, origin = None):
79 return self.to_wire(None, None, origin)
80