Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/dns/rdtypes/nsbase.py: 86%

28 statements  

« 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 

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"""NS-like base classes.""" 

19 

20import dns.exception 

21import dns.immutable 

22import dns.name 

23import dns.rdata 

24 

25 

26@dns.immutable.immutable 

27class NSBase(dns.rdata.Rdata): 

28 

29 """Base class for rdata that is like an NS record.""" 

30 

31 __slots__ = ["target"] 

32 

33 def __init__(self, rdclass, rdtype, target): 

34 super().__init__(rdclass, rdtype) 

35 self.target = self._as_name(target) 

36 

37 def to_text(self, origin=None, relativize=True, **kw): 

38 target = self.target.choose_relativity(origin, relativize) 

39 return str(target) 

40 

41 @classmethod 

42 def from_text( 

43 cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None 

44 ): 

45 target = tok.get_name(origin, relativize, relativize_to) 

46 return cls(rdclass, rdtype, target) 

47 

48 def _to_wire(self, file, compress=None, origin=None, canonicalize=False): 

49 self.target.to_wire(file, compress, origin, canonicalize) 

50 

51 @classmethod 

52 def from_wire_parser(cls, rdclass, rdtype, parser, origin=None): 

53 target = parser.get_name(origin) 

54 return cls(rdclass, rdtype, target) 

55 

56 

57@dns.immutable.immutable 

58class UncompressedNS(NSBase): 

59 

60 """Base class for rdata that is like an NS record, but whose name 

61 is not compressed when convert to DNS wire format, and whose 

62 digestable form is not downcased.""" 

63 

64 def _to_wire(self, file, compress=None, origin=None, canonicalize=False): 

65 self.target.to_wire(file, None, origin, False)