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