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

Source Code for Module dns.rdtypes.nsbase

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