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)  

SOA.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 import struct
19 
20 import dns.exception
21 import dns.rdata
22 import dns.name
23 
24 
26 
27  """SOA record
28 
29  @ivar mname: the SOA MNAME (master name) field
30  @type mname: dns.name.Name object
31  @ivar rname: the SOA RNAME (responsible name) field
32  @type rname: dns.name.Name object
33  @ivar serial: The zone's serial number
34  @type serial: int
35  @ivar refresh: The zone's refresh value (in seconds)
36  @type refresh: int
37  @ivar retry: The zone's retry value (in seconds)
38  @type retry: int
39  @ivar expire: The zone's expiration value (in seconds)
40  @type expire: int
41  @ivar minimum: The zone's negative caching time (in seconds, called
42  "minimum" for historical reasons)
43  @type minimum: int
44  @see: RFC 1035"""
45 
46  __slots__ = ['mname', 'rname', 'serial', 'refresh', 'retry', 'expire',
47  'minimum']
48 
49  def __init__(self, rdclass, rdtype, mname, rname, serial, refresh, retry,
50  expire, minimum):
51  super(SOA, self).__init__(rdclass, rdtype)
52  self.mname = mname
53  self.rname = rname
54  self.serial = serial
55  self.refresh = refresh
56  self.retry = retry
57  self.expire = expire
58  self.minimum = minimum
59 
60  def to_text(self, origin=None, relativize=True, **kw):
61  mname = self.mname.choose_relativity(origin, relativize)
62  rname = self.rname.choose_relativity(origin, relativize)
63  return '%s %s %d %d %d %d %d' % (
64  mname, rname, self.serial, self.refresh, self.retry,
65  self.expire, self.minimum)
66 
67  @classmethod
68  def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
69  mname = tok.get_name()
70  rname = tok.get_name()
71  mname = mname.choose_relativity(origin, relativize)
72  rname = rname.choose_relativity(origin, relativize)
73  serial = tok.get_uint32()
74  refresh = tok.get_ttl()
75  retry = tok.get_ttl()
76  expire = tok.get_ttl()
77  minimum = tok.get_ttl()
78  tok.get_eol()
79  return cls(rdclass, rdtype, mname, rname, serial, refresh, retry,
80  expire, minimum)
81 
82  def to_wire(self, file, compress=None, origin=None):
83  self.mname.to_wire(file, compress, origin)
84  self.rname.to_wire(file, compress, origin)
85  five_ints = struct.pack('!IIIII', self.serial, self.refresh,
86  self.retry, self.expire, self.minimum)
87  file.write(five_ints)
88 
89  def to_digestable(self, origin=None):
90  return self.mname.to_digestable(origin) + \
91  self.rname.to_digestable(origin) + \
92  struct.pack('!IIIII', self.serial, self.refresh,
93  self.retry, self.expire, self.minimum)
94 
95  @classmethod
96  def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
97  (mname, cused) = dns.name.from_wire(wire[: current + rdlen], current)
98  current += cused
99  rdlen -= cused
100  (rname, cused) = dns.name.from_wire(wire[: current + rdlen], current)
101  current += cused
102  rdlen -= cused
103  if rdlen != 20:
105  five_ints = struct.unpack('!IIIII',
106  wire[current: current + rdlen])
107  if origin is not None:
108  mname = mname.relativize(origin)
109  rname = rname.relativize(origin)
110  return cls(rdclass, rdtype, mname, rname,
111  five_ints[0], five_ints[1], five_ints[2], five_ints[3],
112  five_ints[4])
113 
114  def choose_relativity(self, origin=None, relativize=True):
115  self.mname = self.mname.choose_relativity(origin, relativize)
116  self.rname = self.rname.choose_relativity(origin, relativize)
dns.exception.FormError
Definition: exception.py:109
dns.rdtypes.ANY.SOA.SOA.mname
mname
Definition: SOA.py:51
dns.rdtypes.ANY.SOA.SOA.to_digestable
def to_digestable(self, origin=None)
Definition: SOA.py:89
dns.rdtypes.ANY.SOA.SOA.choose_relativity
def choose_relativity(self, origin=None, relativize=True)
Definition: SOA.py:114
dns.rdtypes.ANY.SOA.SOA.to_wire
def to_wire(self, file, compress=None, origin=None)
Definition: SOA.py:82
dns.rdtypes.ANY.SOA.SOA.rname
rname
Definition: SOA.py:52
dns.rdtypes.ANY.SOA.SOA.minimum
minimum
Definition: SOA.py:57
dns.rdtypes.ANY.SOA.SOA.from_text
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True)
Definition: SOA.py:68
dns.rdtypes.ANY.SOA.SOA.retry
retry
Definition: SOA.py:55
dns.rdtypes.ANY.SOA.SOA.serial
serial
Definition: SOA.py:53
dns.name.from_wire
def from_wire(message, current)
Definition: name.py:945
dns.rdtypes.ANY.SOA.SOA.__init__
def __init__(self, rdclass, rdtype, mname, rname, serial, refresh, retry, expire, minimum)
Definition: SOA.py:49
dns.name
Definition: name.py:1
dns.rdtypes.ANY.SOA.SOA.to_text
def to_text(self, origin=None, relativize=True, **kw)
Definition: SOA.py:60
dns.rdtypes.ANY.SOA.SOA.expire
expire
Definition: SOA.py:56
dns.rdata
Definition: rdata.py:1
dns.rdtypes.ANY.SOA.SOA.from_wire
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None)
Definition: SOA.py:96
dns.rdtypes.ANY.SOA.SOA.refresh
refresh
Definition: SOA.py:54
dns.rdtypes.ANY.SOA.SOA
Definition: SOA.py:25
dns.exception
Definition: exception.py:1
dns.rdata.Rdata
Definition: rdata.py:95