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)  

PX.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.name
23 
24 
26 
27  """PX record.
28 
29  @ivar preference: the preference value
30  @type preference: int
31  @ivar map822: the map822 name
32  @type map822: dns.name.Name object
33  @ivar mapx400: the mapx400 name
34  @type mapx400: dns.name.Name object
35  @see: RFC 2163"""
36 
37  __slots__ = ['preference', 'map822', 'mapx400']
38 
39  def __init__(self, rdclass, rdtype, preference, map822, mapx400):
40  super(PX, self).__init__(rdclass, rdtype)
41  self.preference = preference
42  self.map822 = map822
43  self.mapx400 = mapx400
44 
45  def to_text(self, origin=None, relativize=True, **kw):
46  map822 = self.map822.choose_relativity(origin, relativize)
47  mapx400 = self.mapx400.choose_relativity(origin, relativize)
48  return '%d %s %s' % (self.preference, map822, mapx400)
49 
50  @classmethod
51  def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
52  preference = tok.get_uint16()
53  map822 = tok.get_name()
54  map822 = map822.choose_relativity(origin, relativize)
55  mapx400 = tok.get_name(None)
56  mapx400 = mapx400.choose_relativity(origin, relativize)
57  tok.get_eol()
58  return cls(rdclass, rdtype, preference, map822, mapx400)
59 
60  def to_wire(self, file, compress=None, origin=None):
61  pref = struct.pack("!H", self.preference)
62  file.write(pref)
63  self.map822.to_wire(file, None, origin)
64  self.mapx400.to_wire(file, None, origin)
65 
66  @classmethod
67  def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
68  (preference, ) = struct.unpack('!H', wire[current: current + 2])
69  current += 2
70  rdlen -= 2
71  (map822, cused) = dns.name.from_wire(wire[: current + rdlen],
72  current)
73  if cused > rdlen:
75  current += cused
76  rdlen -= cused
77  if origin is not None:
78  map822 = map822.relativize(origin)
79  (mapx400, cused) = dns.name.from_wire(wire[: current + rdlen],
80  current)
81  if cused != rdlen:
83  if origin is not None:
84  mapx400 = mapx400.relativize(origin)
85  return cls(rdclass, rdtype, preference, map822, mapx400)
86 
87  def choose_relativity(self, origin=None, relativize=True):
88  self.map822 = self.map822.choose_relativity(origin, relativize)
89  self.mapx400 = self.mapx400.choose_relativity(origin, relativize)
dns.exception.FormError
Definition: exception.py:109
dns.rdtypes.IN.PX.PX
Definition: PX.py:25
dns.rdtypes.IN.PX.PX.from_wire
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None)
Definition: PX.py:67
dns.rdtypes.IN.PX.PX.preference
preference
Definition: PX.py:41
dns.rdtypes.IN.PX.PX.mapx400
mapx400
Definition: PX.py:43
dns.rdtypes.IN.PX.PX.choose_relativity
def choose_relativity(self, origin=None, relativize=True)
Definition: PX.py:87
dns.rdtypes.IN.PX.PX.__init__
def __init__(self, rdclass, rdtype, preference, map822, mapx400)
Definition: PX.py:39
dns.name.from_wire
def from_wire(message, current)
Definition: name.py:945
dns.rdtypes.IN.PX.PX.map822
map822
Definition: PX.py:42
dns.rdtypes.IN.PX.PX.to_wire
def to_wire(self, file, compress=None, origin=None)
Definition: PX.py:60
dns.name
Definition: name.py:1
dns.rdata
Definition: rdata.py:1
dns.rdtypes.IN.PX.PX.to_text
def to_text(self, origin=None, relativize=True, **kw)
Definition: PX.py:45
dns.rdtypes.IN.PX.PX.from_text
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True)
Definition: PX.py:51
dns.exception
Definition: exception.py:1
dns.rdata.Rdata
Definition: rdata.py:95