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