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  from io import BytesIO 
19   
20  import dns.exception 
21  import dns.rdata 
22  import dns.name 
23 24 25 -class NSBase(dns.rdata.Rdata):
26 27 """Base class for rdata that is like an NS record. 28 29 @ivar target: the target name of the rdata 30 @type target: dns.name.Name object""" 31 32 __slots__ = ['target'] 33
34 - def __init__(self, rdclass, rdtype, target):
35 super(NSBase, self).__init__(rdclass, rdtype) 36 self.target = target
37
38 - def to_text(self, origin=None, relativize=True, **kw):
41 42 @classmethod
43 - def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
48
49 - def to_wire(self, file, compress=None, origin=None):
50 self.target.to_wire(file, compress, origin)
51
52 - def to_digestable(self, origin=None):
53 return self.target.to_digestable(origin)
54 55 @classmethod
56 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
57 (target, cused) = dns.name.from_wire(wire[: current + rdlen], 58 current) 59 if cused != rdlen: 60 raise dns.exception.FormError 61 if origin is not None: 62 target = target.relativize(origin) 63 return cls(rdclass, rdtype, target)
64
65 - def choose_relativity(self, origin=None, relativize=True):
67
68 69 -class UncompressedNS(NSBase):
70 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 f = BytesIO() 80 self.to_wire(f, None, origin) 81 return f.getvalue()
82