dnspython  1.16.0
About: dnspython is a DNS toolkit (for Python 2.x) that supports almost all record types.
  Fossies Dox: dnspython-1.16.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

nsbase.py
Go to the documentation of this file.
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 
20 from io import BytesIO
21 
22 import dns.exception
23 import dns.rdata
24 import dns.name
25 
26 
28 
29  """Base class for rdata that is like an NS record.
30 
31  @ivar target: the target name of the rdata
32  @type target: dns.name.Name object"""
33 
34  __slots__ = ['target']
35 
36  def __init__(self, rdclass, rdtype, target):
37  super(NSBase, self).__init__(rdclass, rdtype)
38  self.target = target
39 
40  def to_text(self, origin=None, relativize=True, **kw):
41  target = self.target.choose_relativity(origin, relativize)
42  return str(target)
43 
44  @classmethod
45  def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
46  target = tok.get_name()
47  target = target.choose_relativity(origin, relativize)
48  tok.get_eol()
49  return cls(rdclass, rdtype, target)
50 
51  def to_wire(self, file, compress=None, origin=None):
52  self.target.to_wire(file, compress, origin)
53 
54  def to_digestable(self, origin=None):
55  return self.target.to_digestable(origin)
56 
57  @classmethod
58  def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
59  (target, cused) = dns.name.from_wire(wire[: current + rdlen],
60  current)
61  if cused != rdlen:
63  if origin is not None:
64  target = target.relativize(origin)
65  return cls(rdclass, rdtype, target)
66 
67  def choose_relativity(self, origin=None, relativize=True):
68  self.target = self.target.choose_relativity(origin, relativize)
69 
70 
72 
73  """Base class for rdata that is like an NS record, but whose name
74  is not compressed when convert to DNS wire format, and whose
75  digestable form is not downcased."""
76 
77  def to_wire(self, file, compress=None, origin=None):
78  super(UncompressedNS, self).to_wire(file, None, origin)
79 
80  def to_digestable(self, origin=None):
81  f = BytesIO()
82  self.to_wire(f, None, origin)
83  return f.getvalue()
dns.rdtypes.nsbase.NSBase.__init__
def __init__(self, rdclass, rdtype, target)
Definition: nsbase.py:36
dns.exception.FormError
Definition: exception.py:109
dns.rdtypes.nsbase.NSBase
Definition: nsbase.py:27
dns.rdtypes.nsbase.UncompressedNS.to_digestable
def to_digestable(self, origin=None)
Definition: nsbase.py:80
dns.rdtypes.nsbase.NSBase.to_wire
def to_wire(self, file, compress=None, origin=None)
Definition: nsbase.py:51
dns.rdtypes.nsbase.UncompressedNS.to_wire
def to_wire(self, file, compress=None, origin=None)
Definition: nsbase.py:77
dns.rdtypes.nsbase.NSBase.from_wire
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None)
Definition: nsbase.py:58
dns.name.from_wire
def from_wire(message, current)
Definition: name.py:945
dns.rdtypes.nsbase.NSBase.from_text
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True)
Definition: nsbase.py:45
dns.rdtypes.nsbase.NSBase.to_text
def to_text(self, origin=None, relativize=True, **kw)
Definition: nsbase.py:40
dns.name
Definition: name.py:1
dns.rdtypes.nsbase.UncompressedNS
Definition: nsbase.py:71
dns.rdtypes.nsbase.NSBase.target
target
Definition: nsbase.py:38
dns.rdata
Definition: rdata.py:1
dns.rdata.Rdata.to_wire
def to_wire(self, file, compress=None, origin=None)
Definition: rdata.py:142
dns.rdtypes.nsbase.NSBase.choose_relativity
def choose_relativity(self, origin=None, relativize=True)
Definition: nsbase.py:67
dns.exception
Definition: exception.py:1
dns.rdtypes.nsbase.NSBase.to_digestable
def to_digestable(self, origin=None)
Definition: nsbase.py:54
dns.rdata.Rdata
Definition: rdata.py:95