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