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

Source Code for Module dns.rdtypes.IN.SRV

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