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)  

A.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 dns.rdtypes.mxbase
19 import struct
20 
22 
23  """A record for Chaosnet
24  @ivar domain: the domain of the address
25  @type domain: dns.name.Name object
26  @ivar address: the 16-bit address
27  @type address: int"""
28 
29  __slots__ = ['domain', 'address']
30 
31  def __init__(self, rdclass, rdtype, address, domain):
32  super(A, self).__init__(rdclass, rdtype, address, domain)
33  self.domain = domain
34  self.address = address
35 
36  def to_text(self, origin=None, relativize=True, **kw):
37  domain = self.domain.choose_relativity(origin, relativize)
38  return '%s %o' % (domain, self.address)
39 
40  @classmethod
41  def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
42  domain = tok.get_name()
43  address = tok.get_uint16(base=8)
44  domain = domain.choose_relativity(origin, relativize)
45  tok.get_eol()
46  return cls(rdclass, rdtype, address, domain)
47 
48  def to_wire(self, file, compress=None, origin=None):
49  self.domain.to_wire(file, compress, origin)
50  pref = struct.pack("!H", self.address)
51  file.write(pref)
52 
53  def to_digestable(self, origin=None):
54  return self.domain.to_digestable(origin) + \
55  struct.pack("!H", self.address)
56 
57  @classmethod
58  def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
59  (domain, cused) = dns.name.from_wire(wire[: current + rdlen-2],
60  current)
61  current += cused
62  (address,) = struct.unpack('!H', wire[current: current + 2])
63  if cused+2 != rdlen:
65  if origin is not None:
66  domain = domain.relativize(origin)
67  return cls(rdclass, rdtype, address, domain)
68 
69  def choose_relativity(self, origin=None, relativize=True):
70  self.domain = self.domain.choose_relativity(origin, relativize)
dns.exception.FormError
Definition: exception.py:109
dns.rdtypes.CH.A.A.from_wire
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None)
Definition: A.py:58
dns.rdtypes.CH.A.A.__init__
def __init__(self, rdclass, rdtype, address, domain)
Definition: A.py:31
dns.rdtypes.mxbase
Definition: mxbase.py:1
dns.rdtypes.mxbase.MXBase
Definition: mxbase.py:28
dns.rdtypes.CH.A.A.domain
domain
Definition: A.py:33
dns.name.from_wire
def from_wire(message, current)
Definition: name.py:945
dns.rdtypes.CH.A.A.to_wire
def to_wire(self, file, compress=None, origin=None)
Definition: A.py:48
dns.rdtypes.CH.A.A
Definition: A.py:21
dns.rdtypes.CH.A.A.from_text
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True)
Definition: A.py:41
dns.rdtypes.CH.A.A.choose_relativity
def choose_relativity(self, origin=None, relativize=True)
Definition: A.py:69
dns.rdtypes.CH.A.A.address
address
Definition: A.py:34
dns.rdtypes.CH.A.A.to_digestable
def to_digestable(self, origin=None)
Definition: A.py:53
dns.rdtypes.CH.A.A.to_text
def to_text(self, origin=None, relativize=True, **kw)
Definition: A.py:36