Package dns :: Package rdtypes :: Package IN :: Module PX
[hide private]
[frames] | no frames]

Source Code for Module dns.rdtypes.IN.PX

  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.name 
 21  import dns.util 
 22   
23 -class PX(dns.rdata.Rdata):
24 """PX record. 25 26 @ivar preference: the preference value 27 @type preference: int 28 @ivar map822: the map822 name 29 @type map822: dns.name.Name object 30 @ivar mapx400: the mapx400 name 31 @type mapx400: dns.name.Name object 32 @see: RFC 2163""" 33 34 __slots__ = ['preference', 'map822', 'mapx400'] 35
36 - def __init__(self, rdclass, rdtype, preference, map822, mapx400):
37 super(PX, self).__init__(rdclass, rdtype) 38 self.preference = preference 39 self.map822 = map822 40 self.mapx400 = mapx400
41
42 - def to_text(self, origin=None, relativize=True, **kw):
43 map822 = self.map822.choose_relativity(origin, relativize) 44 mapx400 = self.mapx400.choose_relativity(origin, relativize) 45 return '%d %s %s' % (self.preference, map822, mapx400)
46
47 - def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
55 56 from_text = classmethod(from_text) 57
58 - def to_wire(self, file, compress = None, origin = None):
59 pref = struct.pack("!H", self.preference) 60 file.write(pref) 61 self.map822.to_wire(file, None, origin) 62 self.mapx400.to_wire(file, None, origin)
63
64 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
65 (preference, ) = struct.unpack('!H', wire[current : current + 2]) 66 current += 2 67 rdlen -= 2 68 (map822, cused) = dns.name.from_wire(wire[: current + rdlen], 69 current) 70 if cused > rdlen: 71 raise dns.exception.FormError 72 current += cused 73 rdlen -= cused 74 if not origin is None: 75 map822 = map822.relativize(origin) 76 (mapx400, cused) = dns.name.from_wire(wire[: current + rdlen], 77 current) 78 if cused != rdlen: 79 raise dns.exception.FormError 80 if not origin is None: 81 mapx400 = mapx400.relativize(origin) 82 return cls(rdclass, rdtype, preference, map822, mapx400)
83 84 from_wire = classmethod(from_wire) 85
86 - def choose_relativity(self, origin = None, relativize = True):
87 self.map822 = self.map822.choose_relativity(origin, relativize) 88 self.mapx400 = self.mapx400.choose_relativity(origin, relativize)
89
90 - def _cmp(self, other):
91 sp = struct.pack("!H", self.preference) 92 op = struct.pack("!H", other.preference) 93 v = dns.util.cmp(sp, op) 94 if v == 0: 95 v = dns.util.cmp(self.map822, other.map822) 96 if v == 0: 97 v = dns.util.cmp(self.mapx400, other.mapx400) 98 return v
99