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

45 statements  

1# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license 

2 

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. 

17 

18"""DNS Rdata Classes.""" 

19 

20import dns.enum 

21import dns.exception 

22 

23 

24class RdataClass(dns.enum.IntEnum): 

25 """DNS Rdata Class""" 

26 

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 

36 

37 @classmethod 

38 def _maximum(cls): 

39 return 65535 

40 

41 @classmethod 

42 def _short_name(cls): 

43 return "class" 

44 

45 @classmethod 

46 def _prefix(cls): 

47 return "CLASS" 

48 

49 @classmethod 

50 def _unknown_exception_class(cls): 

51 return UnknownRdataclass 

52 

53 

54_metaclasses = {RdataClass.NONE, RdataClass.ANY} 

55 

56 

57class UnknownRdataclass(dns.exception.DNSException): 

58 """A DNS class is unknown.""" 

59 

60 

61def from_text(text: str) -> RdataClass: 

62 """Convert text into a DNS rdata class value. 

63 

64 The input text can be a defined DNS RR class mnemonic or 

65 instance of the DNS generic class syntax. 

66 

67 For example, "IN" and "CLASS1" will both result in a value of 1. 

68 

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 """ 

73 

74 return RdataClass.from_text(text) 

75 

76 

77def to_text(value: RdataClass) -> str: 

78 """Convert a DNS rdata class value to text. 

79 

80 If the value has a known mnemonic, it will be used, otherwise the 

81 DNS generic class syntax will be used. 

82 

83 :raises ValueError: If the rdata class value is not >= 0 and <= 65535. 

84 :rtype: str 

85 """ 

86 

87 return RdataClass.to_text(value) 

88 

89 

90def is_metaclass(rdclass: RdataClass) -> bool: 

91 """True if the specified class is a metaclass. 

92 

93 The currently defined metaclasses are ANY and NONE. 

94 

95 :param rdclass: The rdata class to check. 

96 :type rdclass: :py:class:`dns.rdataclass.RdataClass` 

97 """ 

98 

99 if rdclass in _metaclasses: 

100 return True 

101 return False 

102 

103 

104### BEGIN generated RdataClass constants 

105 

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 

115 

116### END generated RdataClass constants