Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/dns/rdataclass.py: 95%
44 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-02 06:07 +0000
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-02 06:07 +0000
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.rdatatype.UnknownRdataclass`` if the class is unknown.
71 Raises ``ValueError`` if the rdata class value is not >= 0 and <= 65535.
73 Returns a ``dns.rdataclass.RdataClass``.
74 """
76 return RdataClass.from_text(text)
79def to_text(value: RdataClass) -> str:
80 """Convert a DNS rdata class value to text.
82 If the value has a known mnemonic, it will be used, otherwise the
83 DNS generic class syntax will be used.
85 Raises ``ValueError`` if the rdata class value is not >= 0 and <= 65535.
87 Returns a ``str``.
88 """
90 return RdataClass.to_text(value)
93def is_metaclass(rdclass: RdataClass) -> bool:
94 """True if the specified class is a metaclass.
96 The currently defined metaclasses are ANY and NONE.
98 *rdclass* is a ``dns.rdataclass.RdataClass``.
99 """
101 if rdclass in _metaclasses:
102 return True
103 return False
106### BEGIN generated RdataClass constants
108RESERVED0 = RdataClass.RESERVED0
109IN = RdataClass.IN
110INTERNET = RdataClass.INTERNET
111CH = RdataClass.CH
112CHAOS = RdataClass.CHAOS
113HS = RdataClass.HS
114HESIOD = RdataClass.HESIOD
115NONE = RdataClass.NONE
116ANY = RdataClass.ANY
118### END generated RdataClass constants