Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/dns/rdtypes/ANY/NSEC.py: 80%
35 statements
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-25 07:09 +0000
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-25 07:09 +0000
1# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
3# Copyright (C) 2004-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.
18import dns.exception
19import dns.immutable
20import dns.name
21import dns.rdata
22import dns.rdatatype
23import dns.rdtypes.util
26@dns.immutable.immutable
27class Bitmap(dns.rdtypes.util.Bitmap):
28 type_name = "NSEC"
31@dns.immutable.immutable
32class NSEC(dns.rdata.Rdata):
34 """NSEC record"""
36 __slots__ = ["next", "windows"]
38 def __init__(self, rdclass, rdtype, next, windows):
39 super().__init__(rdclass, rdtype)
40 self.next = self._as_name(next)
41 if not isinstance(windows, Bitmap):
42 windows = Bitmap(windows)
43 self.windows = tuple(windows.windows)
45 def to_text(self, origin=None, relativize=True, **kw):
46 next = self.next.choose_relativity(origin, relativize)
47 text = Bitmap(self.windows).to_text()
48 return "{}{}".format(next, text)
50 @classmethod
51 def from_text(
52 cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None
53 ):
54 next = tok.get_name(origin, relativize, relativize_to)
55 windows = Bitmap.from_text(tok)
56 return cls(rdclass, rdtype, next, windows)
58 def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
59 # Note that NSEC downcasing, originally mandated by RFC 4034
60 # section 6.2 was removed by RFC 6840 section 5.1.
61 self.next.to_wire(file, None, origin, False)
62 Bitmap(self.windows).to_wire(file)
64 @classmethod
65 def from_wire_parser(cls, rdclass, rdtype, parser, origin=None):
66 next = parser.get_name(origin)
67 bitmap = Bitmap.from_wire_parser(parser)
68 return cls(rdclass, rdtype, next, bitmap)