1
2
3
4
5
6
7
8
9
10
11
12
13
14
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):
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):
60
61 - def to_wire(self, file, compress=None, origin=None):
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
82