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

Source Code for Module dns.rdtypes.ANY.CAA

 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 struct 
17   
18  import dns.exception 
19  import dns.rdata 
20  import dns.tokenizer 
21 22 23 -class CAA(dns.rdata.Rdata):
24 25 """CAA (Certification Authority Authorization) record 26 27 @ivar flags: the flags 28 @type flags: int 29 @ivar tag: the tag 30 @type tag: string 31 @ivar value: the value 32 @type value: string 33 @see: RFC 6844""" 34 35 __slots__ = ['flags', 'tag', 'value'] 36
37 - def __init__(self, rdclass, rdtype, flags, tag, value):
38 super(CAA, self).__init__(rdclass, rdtype) 39 self.flags = flags 40 self.tag = tag 41 self.value = value
42
43 - def to_text(self, origin=None, relativize=True, **kw):
44 return '%u %s "%s"' % (self.flags, 45 dns.rdata._escapify(self.tag), 46 dns.rdata._escapify(self.value))
47 48 @classmethod
49 - def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
50 flags = tok.get_uint8() 51 tag = tok.get_string().encode() 52 if len(tag) > 255: 53 raise dns.exception.SyntaxError("tag too long") 54 if not tag.isalnum(): 55 raise dns.exception.SyntaxError("tag is not alphanumeric") 56 value = tok.get_string().encode() 57 return cls(rdclass, rdtype, flags, tag, value)
58
59 - def to_wire(self, file, compress=None, origin=None):
60 file.write(struct.pack('!B', self.flags)) 61 l = len(self.tag) 62 assert l < 256 63 file.write(struct.pack('!B', l)) 64 file.write(self.tag) 65 file.write(self.value)
66 67 @classmethod
68 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
69 (flags, l) = struct.unpack('!BB', wire[current: current + 2]) 70 current += 2 71 tag = wire[current: current + l] 72 value = wire[current + l:current + rdlen - 2] 73 return cls(rdclass, rdtype, flags, tag, value)
74