Debian Codegraph @

dns/rdtypes/ANY/DSYNC.py

raw
1 # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
2
3 import struct
4
5 import dns.enum
6 import dns.exception
7 import dns.immutable
8 import dns.rdata
9 import dns.rdatatype
10 import dns.rdtypes.util
11
12
13 class UnknownScheme(dns.exception.DNSException):
14 """Unknown DSYNC scheme"""
15
16
17 class Scheme(dns.enum.IntEnum):
18 """DSYNC SCHEME"""
19
20 NOTIFY = 1
21
22 @classmethod
23 def _maximum(cls):
24 return 255
25
26 @classmethod
27 def _unknown_exception_class(cls):
28 return UnknownScheme
29
30
31 @dns.immutable.immutable
32 class DSYNC(dns.rdata.Rdata):
33 """DSYNC record"""
34
35 # see: draft-ietf-dnsop-generalized-notify
36
37 __slots__ = ["rrtype", "scheme", "port", "target"]
38
39 def __init__(self, rdclass, rdtype, rrtype, scheme, port, target):
40 super().__init__(rdclass, rdtype)
41 self.rrtype = self._as_rdatatype(rrtype)
42 self.scheme = Scheme.make(scheme)
43 self.port = self._as_uint16(port)
44 self.target = self._as_name(target)
45
46 def to_text(self, origin=None, relativize=True, **kw):
47 target = self.target.choose_relativity(origin, relativize)
48 return (
49 f"{dns.rdatatype.to_text(self.rrtype)} {Scheme.to_text(self.scheme)} "
50 f"{self.port} {target}"
51 )
52
53 @classmethod
54 def from_text(
55 cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None
56 ):
57 rrtype = dns.rdatatype.from_text(tok.get_string())
58 scheme = Scheme.make(tok.get_string())
59 port = tok.get_uint16()
60 target = tok.get_name(origin, relativize, relativize_to)
61 return cls(rdclass, rdtype, rrtype, scheme, port, target)
62
63 def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
64 three_ints = struct.pack("!HBH", self.rrtype, self.scheme, self.port)
65 file.write(three_ints)
66 self.target.to_wire(file, None, origin, False)
67
68 @classmethod
69 def from_wire_parser(cls, rdclass, rdtype, parser, origin=None):
70 (rrtype, scheme, port) = parser.get_struct("!HBH")
71 target = parser.get_name(origin)
72 return cls(rdclass, rdtype, rrtype, scheme, port, target)