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

Source Code for Module dns.rdtypes.IN.DHCID

 1  # Copyright (C) 2006, 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 base64 
17   
18  import dns.exception 
19  import dns.util 
20   
21 -class DHCID(dns.rdata.Rdata):
22 """DHCID record 23 24 @ivar data: the data (the content of the RR is opaque as far as the 25 DNS is concerned) 26 @type data: bytes 27 @see: RFC 4701""" 28 29 __slots__ = ['data'] 30
31 - def __init__(self, rdclass, rdtype, data):
32 super(DHCID, self).__init__(rdclass, rdtype) 33 self.data = data
34
35 - def to_text(self, origin=None, relativize=True, **kw):
36 return dns.rdata._base64ify(self.data)
37
38 - def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
39 chunks = [] 40 while 1: 41 t = tok.get().unescape() 42 if t.is_eol_or_eof(): 43 break 44 if not t.is_identifier(): 45 raise dns.exception.SyntaxError 46 chunks.append(t.value) 47 b64 = ''.join(chunks) 48 data = base64.b64decode(b64.encode('ascii')) 49 return cls(rdclass, rdtype, data)
50 51 from_text = classmethod(from_text) 52
53 - def to_wire(self, file, compress = None, origin = None):
54 file.write(self.data)
55
56 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
57 data = wire[current : current + rdlen].unwrap() 58 return cls(rdclass, rdtype, data)
59 60 from_wire = classmethod(from_wire) 61
62 - def _cmp(self, other):
63 return dns.util.cmp(self.data, other.data)
64