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