dnspython  1.16.0
About: dnspython is a DNS toolkit (for Python 2.x) that supports almost all record types.
  Fossies Dox: dnspython-1.16.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

HINFO.py
Go to the documentation of this file.
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 
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:
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:
85  os = wire[current: current + l].unwrap()
86  return cls(rdclass, rdtype, cpu, os)
dns.exception.FormError
Definition: exception.py:109
dns.rdtypes.ANY.HINFO.HINFO.to_wire
def to_wire(self, file, compress=None, origin=None)
Definition: HINFO.py:60
dns.rdtypes.ANY.HINFO.HINFO.from_wire
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None)
Definition: HINFO.py:71
dns.rdtypes.ANY.HINFO.HINFO.os
os
Definition: HINFO.py:45
dns.rdtypes.ANY.HINFO.HINFO.from_text
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True)
Definition: HINFO.py:54
dns.rdtypes.ANY.HINFO.HINFO.cpu
cpu
Definition: HINFO.py:41
dns.rdata._escapify
def _escapify(qstring)
Definition: rdata.py:65
dns.rdtypes.ANY.HINFO.HINFO.__init__
def __init__(self, rdclass, rdtype, cpu, os)
Definition: HINFO.py:38
dns.rdtypes.ANY.HINFO.HINFO.to_text
def to_text(self, origin=None, relativize=True, **kw)
Definition: HINFO.py:49
dns.rdata
Definition: rdata.py:1
dns.rdtypes.ANY.HINFO.HINFO
Definition: HINFO.py:26
dns._compat
Definition: _compat.py:1
dns.tokenizer
Definition: tokenizer.py:1
dns.exception
Definition: exception.py:1
dns.rdata.Rdata
Definition: rdata.py:95