Home | Trees | Indices | Help |
|
---|
|
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.name 20 import dns.rdata 21 import dns.util 22 2830 """NAPTR record 31 32 @ivar order: order 33 @type order: int 34 @ivar preference: preference 35 @type preference: int 36 @ivar flags: flags 37 @type flags: string 38 @ivar service: service 39 @type service: string 40 @ivar regexp: regular expression 41 @type regexp: string 42 @ivar replacement: replacement name 43 @type replacement: dns.name.Name object 44 @see: RFC 3403""" 45 46 __slots__ = ['order', 'preference', 'flags', 'service', 'regexp', 47 'replacement'] 4813349 - def __init__(self, rdclass, rdtype, order, preference, flags, service, 50 regexp, replacement):51 super(NAPTR, self).__init__(rdclass, rdtype) 52 self.order = order 53 self.preference = preference 54 self.flags = flags 55 self.service = service 56 self.regexp = regexp 57 self.replacement = replacement5860 replacement = self.replacement.choose_relativity(origin, relativize) 61 return '%d %d "%s" "%s" "%s" %s' % \ 62 (self.order, self.preference, 63 dns.rdata._escapify(self.flags), 64 dns.rdata._escapify(self.service), 65 dns.rdata._escapify(self.regexp), 66 self.replacement)6769 order = tok.get_uint16() 70 preference = tok.get_uint16() 71 flags = tok.get_string() 72 service = tok.get_string() 73 regexp = tok.get_string() 74 replacement = tok.get_name() 75 replacement = replacement.choose_relativity(origin, relativize) 76 tok.get_eol() 77 return cls(rdclass, rdtype, order, preference, flags, service, 78 regexp, replacement)79 80 from_text = classmethod(from_text) 8183 two_ints = struct.pack("!HH", self.order, self.preference) 84 file.write(two_ints) 85 _write_string(file, self.flags) 86 _write_string(file, self.service) 87 _write_string(file, self.regexp) 88 self.replacement.to_wire(file, compress, origin)8991 (order, preference) = struct.unpack('!HH', wire[current : current + 4]) 92 current += 4 93 rdlen -= 4 94 strings = [] 95 for i in range(3): 96 l = wire[current] 97 current += 1 98 rdlen -= 1 99 if l > rdlen or rdlen < 0: 100 raise dns.exception.FormError 101 s = wire[current : current + l].decode('latin_1') 102 current += l 103 rdlen -= l 104 strings.append(s) 105 (replacement, cused) = dns.name.from_wire(wire[: current + rdlen], 106 current) 107 if cused != rdlen: 108 raise dns.exception.FormError 109 if not origin is None: 110 replacement = replacement.relativize(origin) 111 return cls(rdclass, rdtype, order, preference, strings[0], strings[1], 112 strings[2], replacement)113 114 from_wire = classmethod(from_wire) 115 119121 sp = struct.pack("!HH", self.order, self.preference) 122 op = struct.pack("!HH", other.order, other.preference) 123 v = dns.util.cmp(sp, op) 124 if v == 0: 125 v = dns.util.cmp(self.flags, other.flags) 126 if v == 0: 127 v = dns.util.cmp(self.service, other.service) 128 if v == 0: 129 v = dns.util.cmp(self.regexp, other.regexp) 130 if v == 0: 131 v = dns.util.cmp(self.replacement, other.replacement) 132 return v
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sun Mar 31 05:21:21 2013 | http://epydoc.sourceforge.net |