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

Source Code for Module dns.rdtypes.IN.SRV

 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 22 23 -class SRV(dns.rdata.Rdata):
24 25 """SRV record 26 27 @ivar priority: the priority 28 @type priority: int 29 @ivar weight: the weight 30 @type weight: int 31 @ivar port: the port of the service 32 @type port: int 33 @ivar target: the target host 34 @type target: dns.name.Name object 35 @see: RFC 2782""" 36 37 __slots__ = ['priority', 'weight', 'port', 'target'] 38
39 - def __init__(self, rdclass, rdtype, priority, weight, port, target):
40 super(SRV, self).__init__(rdclass, rdtype) 41 self.priority = priority 42 self.weight = weight 43 self.port = port 44 self.target = target
45
46 - def to_text(self, origin=None, relativize=True, **kw):
47 target = self.target.choose_relativity(origin, relativize) 48 return '%d %d %d %s' % (self.priority, self.weight, self.port, 49 target)
50 51 @classmethod
52 - def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
53 priority = tok.get_uint16() 54 weight = tok.get_uint16() 55 port = tok.get_uint16() 56 target = tok.get_name(None) 57 target = target.choose_relativity(origin, relativize) 58 tok.get_eol() 59 return cls(rdclass, rdtype, priority, weight, port, target)
60
61 - def to_wire(self, file, compress=None, origin=None):
62 three_ints = struct.pack("!HHH", self.priority, self.weight, self.port) 63 file.write(three_ints) 64 self.target.to_wire(file, compress, origin)
65 66 @classmethod
67 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
68 (priority, weight, port) = struct.unpack('!HHH', 69 wire[current: current + 6]) 70 current += 6 71 rdlen -= 6 72 (target, cused) = dns.name.from_wire(wire[: current + rdlen], 73 current) 74 if cused != rdlen: 75 raise dns.exception.FormError 76 if origin is not None: 77 target = target.relativize(origin) 78 return cls(rdclass, rdtype, priority, weight, port, target)
79
80 - def choose_relativity(self, origin=None, relativize=True):
82