Debian Codegraph @

dns/rdtypes/CH/A.py

raw
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.immutable
21 import dns.rdata
22 import dns.rdtypes.mxbase
23
24
25 @dns.immutable.immutable
26 class A(dns.rdata.Rdata):
27 """A record for Chaosnet"""
28
29 # domain: the domain of the address
30 # address: the 16-bit address
31
32 __slots__ = ["domain", "address"]
33
34 def __init__(self, rdclass, rdtype, domain, address):
35 super().__init__(rdclass, rdtype)
36 self.domain = self._as_name(domain)
37 self.address = self._as_uint16(address)
38
39 def to_text(self, origin=None, relativize=True, **kw):
40 domain = self.domain.choose_relativity(origin, relativize)
41 return f"{domain} {self.address:o}"
42
43 @classmethod
44 def from_text(
45 cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None
46 ):
47 domain = tok.get_name(origin, relativize, relativize_to)
48 address = tok.get_uint16(base=8)
49 return cls(rdclass, rdtype, domain, address)
50
51 def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
52 self.domain.to_wire(file, compress, origin, canonicalize)
53 pref = struct.pack("!H", self.address)
54 file.write(pref)
55
56 @classmethod
57 def from_wire_parser(cls, rdclass, rdtype, parser, origin=None):
58 domain = parser.get_name(origin)
59 address = parser.get_uint16()
60 return cls(rdclass, rdtype, domain, address)