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

Source Code for Module dns.rdtypes.ANY.HINFO

 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 dns.exception 
17  import dns.rdata 
18  import dns.tokenizer 
19  import dns.util 
20   
21 -class HINFO(dns.rdata.Rdata):
22 """HINFO record 23 24 @ivar cpu: the CPU type 25 @type cpu: string 26 @ivar os: the OS type 27 @type os: string 28 @see: RFC 1035""" 29 30 __slots__ = ['cpu', 'os'] 31
32 - def __init__(self, rdclass, rdtype, cpu, os):
33 super(HINFO, self).__init__(rdclass, rdtype) 34 self.cpu = cpu 35 self.os = os
36
37 - def to_text(self, origin=None, relativize=True, **kw):
38 return '"%s" "%s"' % (dns.rdata._escapify(self.cpu), 39 dns.rdata._escapify(self.os))
40
41 - def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
42 cpu = tok.get_string() 43 os = tok.get_string() 44 tok.get_eol() 45 return cls(rdclass, rdtype, cpu, os)
46 47 from_text = classmethod(from_text) 48
49 - def to_wire(self, file, compress = None, origin = None):
50 l = len(self.cpu) 51 assert l < 256 52 dns.util.write_uint8(file, l) 53 file.write(self.cpu.encode('latin_1')) 54 l = len(self.os) 55 assert l < 256 56 dns.util.write_uint8(file, l) 57 file.write(self.os.encode('latin_1'))
58
59 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
60 l = wire[current] 61 current += 1 62 rdlen -= 1 63 if l > rdlen: 64 raise dns.exception.FormError 65 cpu = wire[current : current + l].decode('latin_1') 66 current += l 67 rdlen -= l 68 l = wire[current] 69 current += 1 70 rdlen -= 1 71 if l != rdlen: 72 raise dns.exception.FormError 73 os = wire[current : current + l].decode('latin_1') 74 return cls(rdclass, rdtype, cpu, os)
75 76 from_wire = classmethod(from_wire) 77
78 - def _cmp(self, other):
79 v = dns.util.cmp(self.cpu, other.cpu) 80 if v == 0: 81 v = dns.util.cmp(self.os, other.os) 82 return v
83