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

Source Code for Module dns.rdtypes.ANY.CAA

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