Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/dns/rdataclass.py: 78%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
3# Copyright (C) 2001-2017 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.
18"""DNS Rdata Classes."""
20import dns.enum
21import dns.exception
24class RdataClass(dns.enum.IntEnum):
25 """DNS Rdata Class"""
27 RESERVED0 = 0
28 IN = 1
29 INTERNET = IN
30 CH = 3
31 CHAOS = CH
32 HS = 4
33 HESIOD = HS
34 NONE = 254
35 ANY = 255
37 @classmethod
38 def _maximum(cls):
39 return 65535
41 @classmethod
42 def _short_name(cls):
43 return "class"
45 @classmethod
46 def _prefix(cls):
47 return "CLASS"
49 @classmethod
50 def _unknown_exception_class(cls):
51 return UnknownRdataclass
54_metaclasses = {RdataClass.NONE, RdataClass.ANY}
57class UnknownRdataclass(dns.exception.DNSException):
58 """A DNS class is unknown."""
61def from_text(text: str) -> RdataClass:
62 """Convert text into a DNS rdata class value.
64 The input text can be a defined DNS RR class mnemonic or
65 instance of the DNS generic class syntax.
67 For example, "IN" and "CLASS1" will both result in a value of 1.
69 :raises dns.rdataclass.UnknownRdataclass: If the class is unknown.
70 :raises ValueError: If the rdata class value is not >= 0 and <= 65535.
71 :rtype: :py:class:`dns.rdataclass.RdataClass`
72 """
74 return RdataClass.from_text(text)
77def to_text(value: RdataClass) -> str:
78 """Convert a DNS rdata class value to text.
80 If the value has a known mnemonic, it will be used, otherwise the
81 DNS generic class syntax will be used.
83 :raises ValueError: If the rdata class value is not >= 0 and <= 65535.
84 :rtype: str
85 """
87 return RdataClass.to_text(value)
90def is_metaclass(rdclass: RdataClass) -> bool:
91 """True if the specified class is a metaclass.
93 The currently defined metaclasses are ANY and NONE.
95 :param rdclass: The rdata class to check.
96 :type rdclass: :py:class:`dns.rdataclass.RdataClass`
97 """
99 if rdclass in _metaclasses:
100 return True
101 return False
104### BEGIN generated RdataClass constants
106RESERVED0 = RdataClass.RESERVED0
107IN = RdataClass.IN
108INTERNET = RdataClass.INTERNET
109CH = RdataClass.CH
110CHAOS = RdataClass.CHAOS
111HS = RdataClass.HS
112HESIOD = RdataClass.HESIOD
113NONE = RdataClass.NONE
114ANY = RdataClass.ANY
116### END generated RdataClass constants