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)  

dns.zone.Zone Class Reference
Inheritance diagram for dns.zone.Zone:
[legend]
Collaboration diagram for dns.zone.Zone:
[legend]

Public Member Functions

def __init__ (self, origin, rdclass=dns.rdataclass.IN, relativize=True)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __getitem__ (self, key)
 
def __setitem__ (self, key, value)
 
def __delitem__ (self, key)
 
def __iter__ (self)
 
def iterkeys (self)
 
def keys (self)
 
def itervalues (self)
 
def values (self)
 
def items (self)
 
def get (self, key)
 
def __contains__ (self, other)
 
def find_node (self, name, create=False)
 
def get_node (self, name, create=False)
 
def delete_node (self, name)
 
def find_rdataset (self, name, rdtype, covers=dns.rdatatype.NONE, create=False)
 
def get_rdataset (self, name, rdtype, covers=dns.rdatatype.NONE, create=False)
 
def delete_rdataset (self, name, rdtype, covers=dns.rdatatype.NONE)
 
def replace_rdataset (self, name, replacement)
 
def find_rrset (self, name, rdtype, covers=dns.rdatatype.NONE)
 
def get_rrset (self, name, rdtype, covers=dns.rdatatype.NONE)
 
def iterate_rdatasets (self, rdtype=dns.rdatatype.ANY, covers=dns.rdatatype.NONE)
 
def iterate_rdatas (self, rdtype=dns.rdatatype.ANY, covers=dns.rdatatype.NONE)
 
def to_file (self, f, sorted=True, relativize=True, nl=None)
 
def to_text (self, sorted=True, relativize=True, nl=None)
 
def check_origin (self)
 

Public Attributes

 origin
 
 rdclass
 
 nodes
 
 relativize
 

Static Public Attributes

 node_factory = dns.node.Node
 
def iteritems = items
 

Private Member Functions

def _validate_name (self, name)
 

Static Private Attributes

list __slots__ = ['rdclass', 'origin', 'nodes', 'relativize']
 

Detailed Description

A DNS zone.

A Zone is a mapping from names to nodes.  The zone object may be
treated like a Python dictionary, e.g. zone[name] will retrieve
the node associated with that name.  The I{name} may be a
dns.name.Name object, or it may be a string.  In the either case,
if the name is relative it is treated as relative to the origin of
the zone.

@ivar rdclass: The zone's rdata class; the default is class IN.
@type rdclass: int
@ivar origin: The origin of the zone.
@type origin: dns.name.Name object
@ivar nodes: A dictionary mapping the names of nodes in the zone to the
nodes themselves.
@type nodes: dict
@ivar relativize: should names in the zone be relativized?
@type relativize: bool
@cvar node_factory: the factory used to create a new node
@type node_factory: class or callable

Definition at line 61 of file zone.py.

Constructor & Destructor Documentation

◆ __init__()

def dns.zone.Zone.__init__ (   self,
  origin,
  rdclass = dns.rdataclass.IN,
  relativize = True 
)
Initialize a zone object.

@param origin: The origin of the zone.
@type origin: dns.name.Name object
@param rdclass: The zone's rdata class; the default is class IN.
@type rdclass: int

Definition at line 89 of file zone.py.

References dns.name.from_text().

Member Function Documentation

◆ __contains__()

def dns.zone.Zone.__contains__ (   self,
  other 
)

Definition at line 186 of file zone.py.

References dns.zone.Zone.nodes.

◆ __delitem__()

def dns.zone.Zone.__delitem__ (   self,
  key 
)

Definition at line 152 of file zone.py.

References dns.zone.Zone._validate_name(), and dns.zone.Zone.nodes.

◆ __eq__()

def dns.zone.Zone.__eq__ (   self,
  other 
)

◆ __getitem__()

def dns.zone.Zone.__getitem__ (   self,
  key 
)

Definition at line 144 of file zone.py.

References dns.zone.Zone._validate_name(), and dns.zone.Zone.nodes.

◆ __iter__()

def dns.zone.Zone.__iter__ (   self)

Definition at line 156 of file zone.py.

References dns.zone.Zone.nodes.

◆ __ne__()

◆ __setitem__()

def dns.zone.Zone.__setitem__ (   self,
  key,
  value 
)

Definition at line 148 of file zone.py.

References dns.zone.Zone._validate_name(), and dns.zone.Zone.nodes.

◆ _validate_name()

◆ check_origin()

def dns.zone.Zone.check_origin (   self)
Do some simple checking of the zone's origin.

@raises dns.zone.NoSOA: there is no SOA RR
@raises dns.zone.NoNS: there is no NS RRset
@raises KeyError: there is no origin node

Definition at line 569 of file zone.py.

References dns.node.Node.get_rdataset(), dns.zone.Zone.get_rdataset(), dns.update.Update.origin, dns.renderer.Renderer.origin, dns.zone.Zone.origin, dns.message.Message.origin, and dns.zone.Zone.relativize.

◆ delete_node()

def dns.zone.Zone.delete_node (   self,
  name 
)
Delete the specified node if it exists.

It is not an error if the node does not exist.

Definition at line 229 of file zone.py.

References dns.zone.Zone._validate_name(), and dns.zone.Zone.nodes.

Referenced by dns.zone.Zone.delete_rdataset().

◆ delete_rdataset()

def dns.zone.Zone.delete_rdataset (   self,
  name,
  rdtype,
  covers = dns.rdatatype.NONE 
)
Delete the rdataset matching I{rdtype} and I{covers}, if it
exists at the node specified by I{name}.

The I{name}, I{rdtype}, and I{covers} parameters may be
strings, in which case they will be converted to their proper
type.

It is not an error if the node does not exist, or if there is no
matching rdataset at the node.

If the node has no rdatasets after the deletion, it will itself
be deleted.

@param name: the owner name to look for
@type name: DNS.name.Name object or string
@param rdtype: the rdata type desired
@type rdtype: int or string
@param covers: the covered type (defaults to None)
@type covers: int or string

Definition at line 308 of file zone.py.

References dns.zone.Zone._validate_name(), dns.zone.Zone.delete_node(), dns.rdatatype.from_text(), dns.zone.Zone.get_node(), dns.rdataset.Rdataset.rdclass, dns.zone.Zone.rdclass, dns.rdata.Rdata.rdclass, and dns.resolver.Answer.rdclass.

◆ find_node()

def dns.zone.Zone.find_node (   self,
  name,
  create = False 
)
Find a node in the zone, possibly creating it.

@param name: the name of the node to find
@type name: dns.name.Name object or string
@param create: should the node be created if it doesn't exist?
@type create: bool
@raises KeyError: the name is not known and create was not specified.
@rtype: dns.node.Node object

Definition at line 189 of file zone.py.

References dns.zone.Zone._validate_name(), dns.zone.Zone.get(), dns.zone.Zone.node_factory, and dns.zone.Zone.nodes.

Referenced by dns.zone.Zone.find_rdataset(), dns.zone.Zone.get_node(), and dns.zone.Zone.replace_rdataset().

◆ find_rdataset()

def dns.zone.Zone.find_rdataset (   self,
  name,
  rdtype,
  covers = dns.rdatatype.NONE,
  create = False 
)
Look for rdata with the specified name and type in the zone,
and return an rdataset encapsulating it.

The I{name}, I{rdtype}, and I{covers} parameters may be
strings, in which case they will be converted to their proper
type.

The rdataset returned is not a copy; changes to it will change
the zone.

KeyError is raised if the name or type are not found.
Use L{get_rdataset} if you want to have None returned instead.

@param name: the owner name to look for
@type name: DNS.name.Name object or string
@param rdtype: the rdata type desired
@type rdtype: int or string
@param covers: the covered type (defaults to None)
@type covers: int or string
@param create: should the node and rdataset be created if they do not
exist?
@type create: bool
@raises KeyError: the node or rdata could not be found
@rtype: dns.rdataset.Rdataset object

Definition at line 239 of file zone.py.

References dns.zone.Zone._validate_name(), dns.zone.Zone.find_node(), dns.rdatatype.from_text(), dns.rdataset.Rdataset.rdclass, dns.zone.Zone.rdclass, dns.rdata.Rdata.rdclass, and dns.resolver.Answer.rdclass.

Referenced by dns.zone.Zone.find_rrset(), and dns.zone.Zone.get_rdataset().

◆ find_rrset()

def dns.zone.Zone.find_rrset (   self,
  name,
  rdtype,
  covers = dns.rdatatype.NONE 
)
Look for rdata with the specified name and type in the zone,
and return an RRset encapsulating it.

The I{name}, I{rdtype}, and I{covers} parameters may be
strings, in which case they will be converted to their proper
type.

This method is less efficient than the similar
L{find_rdataset} because it creates an RRset instead of
returning the matching rdataset.  It may be more convenient
for some uses since it returns an object which binds the owner
name to the rdata.

This method may not be used to create new nodes or rdatasets;
use L{find_rdataset} instead.

KeyError is raised if the name or type are not found.
Use L{get_rrset} if you want to have None returned instead.

@param name: the owner name to look for
@type name: DNS.name.Name object or string
@param rdtype: the rdata type desired
@type rdtype: int or string
@param covers: the covered type (defaults to None)
@type covers: int or string
@raises KeyError: the node or rdata could not be found
@rtype: dns.rrset.RRset object

Definition at line 363 of file zone.py.

References dns.zone.Zone._validate_name(), dns.zone.Zone.find_rdataset(), dns.rdatatype.from_text(), dns.zone.Zone.nodes, dns.rdataset.Rdataset.rdclass, dns.zone.Zone.rdclass, dns.rdata.Rdata.rdclass, and dns.resolver.Answer.rdclass.

Referenced by dns.zone.Zone.get_rrset().

◆ get()

def dns.zone.Zone.get (   self,
  key 
)

Definition at line 182 of file zone.py.

References dns.zone.Zone._validate_name(), and dns.zone.Zone.nodes.

Referenced by dns.zone.Zone.find_node().

◆ get_node()

def dns.zone.Zone.get_node (   self,
  name,
  create = False 
)
Get a node in the zone, possibly creating it.

This method is like L{find_node}, except it returns None instead
of raising an exception if the node does not exist and creation
has not been requested.

@param name: the name of the node to find
@type name: dns.name.Name object or string
@param create: should the node be created if it doesn't exist?
@type create: bool
@rtype: dns.node.Node object or None

Definition at line 209 of file zone.py.

References dns.zone.Zone.find_node().

Referenced by dns.zone.Zone.delete_rdataset().

◆ get_rdataset()

def dns.zone.Zone.get_rdataset (   self,
  name,
  rdtype,
  covers = dns.rdatatype.NONE,
  create = False 
)
Look for rdata with the specified name and type in the zone,
and return an rdataset encapsulating it.

The I{name}, I{rdtype}, and I{covers} parameters may be
strings, in which case they will be converted to their proper
type.

The rdataset returned is not a copy; changes to it will change
the zone.

None is returned if the name or type are not found.
Use L{find_rdataset} if you want to have KeyError raised instead.

@param name: the owner name to look for
@type name: DNS.name.Name object or string
@param rdtype: the rdata type desired
@type rdtype: int or string
@param covers: the covered type (defaults to None)
@type covers: int or string
@param create: should the node and rdataset be created if they do not
exist?
@type create: bool
@rtype: dns.rdataset.Rdataset object or None

Definition at line 275 of file zone.py.

References dns.node.Node.find_rdataset(), and dns.zone.Zone.find_rdataset().

Referenced by dns.zone.Zone.check_origin().

◆ get_rrset()

def dns.zone.Zone.get_rrset (   self,
  name,
  rdtype,
  covers = dns.rdatatype.NONE 
)
Look for rdata with the specified name and type in the zone,
and return an RRset encapsulating it.

The I{name}, I{rdtype}, and I{covers} parameters may be
strings, in which case they will be converted to their proper
type.

This method is less efficient than the similar L{get_rdataset}
because it creates an RRset instead of returning the matching
rdataset.  It may be more convenient for some uses since it
returns an object which binds the owner name to the rdata.

This method may not be used to create new nodes or rdatasets;
use L{find_rdataset} instead.

None is returned if the name or type are not found.
Use L{find_rrset} if you want to have KeyError raised instead.

@param name: the owner name to look for
@type name: DNS.name.Name object or string
@param rdtype: the rdata type desired
@type rdtype: int or string
@param covers: the covered type (defaults to None)
@type covers: int or string
@rtype: dns.rrset.RRset object

Definition at line 403 of file zone.py.

References dns.message.Message.find_rrset(), and dns.zone.Zone.find_rrset().

◆ items()

def dns.zone.Zone.items (   self)

Definition at line 177 of file zone.py.

References dns.zone.Zone.nodes.

◆ iterate_rdatas()

def dns.zone.Zone.iterate_rdatas (   self,
  rdtype = dns.rdatatype.ANY,
  covers = dns.rdatatype.NONE 
)
Return a generator which yields (name, ttl, rdata) tuples for
all rdatas in the zone which have the specified I{rdtype}
and I{covers}.  If I{rdtype} is dns.rdatatype.ANY, the default,
then all rdatas will be matched.

@param rdtype: int or string
@type rdtype: int or string
@param covers: the covered type (defaults to None)
@type covers: int or string

Definition at line 460 of file zone.py.

References dns.rdatatype.from_text(), and dns.zone.Zone.iteritems.

◆ iterate_rdatasets()

def dns.zone.Zone.iterate_rdatasets (   self,
  rdtype = dns.rdatatype.ANY,
  covers = dns.rdatatype.NONE 
)
Return a generator which yields (name, rdataset) tuples for
all rdatasets in the zone which have the specified I{rdtype}
and I{covers}.  If I{rdtype} is dns.rdatatype.ANY, the default,
then all rdatasets will be matched.

@param rdtype: int or string
@type rdtype: int or string
@param covers: the covered type (defaults to None)
@type covers: int or string

Definition at line 437 of file zone.py.

References dns.rdatatype.from_text(), and dns.zone.Zone.iteritems.

◆ iterkeys()

def dns.zone.Zone.iterkeys (   self)

Definition at line 159 of file zone.py.

References dns.zone.Zone.keys(), and dns.zone.Zone.nodes.

Referenced by dns.zone.Zone.to_file().

◆ itervalues()

def dns.zone.Zone.itervalues (   self)

Definition at line 168 of file zone.py.

References dns.zone.Zone.nodes, and dns.zone.Zone.values().

◆ keys()

def dns.zone.Zone.keys (   self)

Definition at line 165 of file zone.py.

References dns.zone.Zone.nodes.

Referenced by dns.zone.Zone.iterkeys(), and dns.zone.Zone.to_file().

◆ replace_rdataset()

def dns.zone.Zone.replace_rdataset (   self,
  name,
  replacement 
)
Replace an rdataset at name.

It is not an error if there is no rdataset matching I{replacement}.

Ownership of the I{replacement} object is transferred to the zone;
in other words, this method does not store a copy of I{replacement}
at the node, it stores I{replacement} itself.

If the I{name} node does not exist, it is created.

@param name: the owner name
@type name: DNS.name.Name object or string
@param replacement: the replacement rdataset
@type replacement: dns.rdataset.Rdataset

Definition at line 341 of file zone.py.

References dns.zone.Zone.find_node(), dns.rdataset.Rdataset.rdclass, dns.zone.Zone.rdclass, dns.rdata.Rdata.rdclass, and dns.resolver.Answer.rdclass.

◆ to_file()

def dns.zone.Zone.to_file (   self,
  f,
  sorted = True,
  relativize = True,
  nl = None 
)
Write a zone to a file.

@param f: file or string.  If I{f} is a string, it is treated
as the name of a file to open.
@param sorted: if True, the file will be written with the
names sorted in DNSSEC order from least to greatest.  Otherwise
the names will be written in whatever order they happen to have
in the zone's dictionary.
@param relativize: if True, domain names in the output will be
relativized to the zone's origin (if possible).
@type relativize: bool
@param nl: The end of line string.  If not specified, the
output will use the platform's native end-of-line marker (i.e.
LF on POSIX, CRLF on Windows, CR on Macintosh).
@type nl: string or None

Definition at line 484 of file zone.py.

References dns.zone.Zone.iterkeys(), std::map< K, T >.keys, std::unordered_multimap< K, T >.keys, std::unordered_multiset< K >.keys, std::unordered_map< K, T >.keys, std::set< K >.keys, std::multimap< K, T >.keys, std::unordered_set< K >.keys, std::multiset< K >.keys, dns.zone.Zone.keys(), dns.update.Update.origin, dns.renderer.Renderer.origin, dns.zone.Zone.origin, dns.message.Message.origin, and dns.zone.Zone.to_text().

Referenced by dns.zone.Zone.to_text().

◆ to_text()

def dns.zone.Zone.to_text (   self,
  sorted = True,
  relativize = True,
  nl = None 
)
Return a zone's text as though it were written to a file.

@param sorted: if True, the file will be written with the
names sorted in DNSSEC order from least to greatest.  Otherwise
the names will be written in whatever order they happen to have
in the zone's dictionary.
@param relativize: if True, domain names in the output will be
relativized to the zone's origin (if possible).
@type relativize: bool
@param nl: The end of line string.  If not specified, the
output will use the platform's native end-of-line marker (i.e.
LF on POSIX, CRLF on Windows, CR on Macintosh).
@type nl: string or None

Definition at line 548 of file zone.py.

References dns.zone.Zone.to_file().

Referenced by dns.zone.Zone.to_file().

◆ values()

def dns.zone.Zone.values (   self)

Definition at line 174 of file zone.py.

References dns.zone.Zone.nodes.

Referenced by dns.zone.Zone.itervalues().

Member Data Documentation

◆ __slots__

list dns.zone.Zone.__slots__ = ['rdclass', 'origin', 'nodes', 'relativize']
staticprivate

Definition at line 87 of file zone.py.

◆ iteritems

def dns.zone.Zone.iteritems = items
static

Definition at line 180 of file zone.py.

Referenced by dns.zone.Zone.iterate_rdatas(), and dns.zone.Zone.iterate_rdatasets().

◆ node_factory

dns.zone.Zone.node_factory = dns.node.Node
static

Definition at line 85 of file zone.py.

Referenced by dns.zone.Zone.find_node().

◆ nodes

◆ origin

dns.zone.Zone.origin

◆ rdclass

◆ relativize


The documentation for this class was generated from the following file: