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

Source Code for Module dns.rdtypes.ANY.HINFO

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