Package dns :: Module zone :: Class Zone
[hide private]
[frames] | no frames]

Class Zone

source code

object --+
         |
        Zone

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

Nested Classes [hide private]
class or callable node_factory
the factory used to create a new node
Instance Methods [hide private]
 
__init__(self, origin, rdclass=1, relativize=True)
Initialize a zone object.
source code
bool
__eq__(self, other)
Two zones are equal if they have the same origin, class, and nodes.
source code
bool
__ne__(self, other)
Are two zones not equal?
source code
 
_validate_name(self, name) source code
 
__getitem__(self, key) source code
 
__setitem__(self, key, value) source code
 
__delitem__(self, key) source code
 
__iter__(self) source code
 
iterkeys(self) source code
 
keys(self) source code
 
itervalues(self) source code
 
values(self) source code
 
items(self) source code
 
iteritems(self) source code
 
get(self, key) source code
 
__contains__(self, other) source code
dns.node.Node object
find_node(self, name, create=False)
Find a node in the zone, possibly creating it.
source code
dns.node.Node object or None
get_node(self, name, create=False)
Get a node in the zone, possibly creating it.
source code
 
delete_node(self, name)
Delete the specified node if it exists.
source code
dns.rdataset.Rdataset object
find_rdataset(self, name, rdtype, covers=0, create=False)
Look for rdata with the specified name and type in the zone, and return an rdataset encapsulating it.
source code
dns.rdataset.Rdataset object or None
get_rdataset(self, name, rdtype, covers=0, create=False)
Look for rdata with the specified name and type in the zone, and return an rdataset encapsulating it.
source code
 
delete_rdataset(self, name, rdtype, covers=0)
Delete the rdataset matching rdtype and covers, if it exists at the node specified by name.
source code
 
replace_rdataset(self, name, replacement)
Replace an rdataset at name.
source code
dns.rrset.RRset object
find_rrset(self, name, rdtype, covers=0)
Look for rdata with the specified name and type in the zone, and return an RRset encapsulating it.
source code
dns.rrset.RRset object
get_rrset(self, name, rdtype, covers=0)
Look for rdata with the specified name and type in the zone, and return an RRset encapsulating it.
source code
 
iterate_rdatasets(self, rdtype=255, covers=0)
Return a generator which yields (name, rdataset) tuples for all rdatasets in the zone which have the specified rdtype and covers.
source code
 
iterate_rdatas(self, rdtype=255, covers=0)
Return a generator which yields (name, ttl, rdata) tuples for all rdatas in the zone which have the specified rdtype and covers.
source code
 
to_file(self, f, sorted=True, relativize=True, nl=None)
Write a zone to a file.
source code
 
to_text(self, sorted=True, relativize=True, nl=None)
Return a zone's text as though it were written to a file.
source code
 
check_origin(self)
Do some simple checking of the zone's origin.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables [hide private]
dict nodes
A dictionary mapping the names of nodes in the zone to the nodes themselves.
dns.name.Name object origin
The origin of the zone.
int rdclass
The zone's rdata class; the default is class IN.
bool relativize
should names in the zone be relativized?
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, origin, rdclass=1, relativize=True)
(Constructor)

source code 

Initialize a zone object.

Parameters:
  • origin (dns.name.Name object) - The origin of the zone.
  • rdclass (int) - The zone's rdata class; the default is class IN.
Overrides: object.__init__

find_node(self, name, create=False)

source code 

Find a node in the zone, possibly creating it.

Parameters:
  • name (dns.name.Name object or string) - the name of the node to find
  • create (bool) - should the node be created if it doesn't exist?
Returns: dns.node.Node object
Raises:
  • KeyError - the name is not known and create was not specified.

get_node(self, name, create=False)

source code 

Get a node in the zone, possibly creating it.

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

Parameters:
  • name (dns.name.Name object or string) - the name of the node to find
  • create (bool) - should the node be created if it doesn't exist?
Returns: dns.node.Node object or None

delete_node(self, name)

source code 

Delete the specified node if it exists.

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

find_rdataset(self, name, rdtype, covers=0, create=False)

source code 

Look for rdata with the specified name and type in the zone, and return an rdataset encapsulating it.

The name, rdtype, and 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 get_rdataset if you want to have None returned instead.

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

get_rdataset(self, name, rdtype, covers=0, create=False)

source code 

Look for rdata with the specified name and type in the zone, and return an rdataset encapsulating it.

The name, rdtype, and 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 find_rdataset if you want to have KeyError raised instead.

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

delete_rdataset(self, name, rdtype, covers=0)

source code 

Delete the rdataset matching rdtype and covers, if it exists at the node specified by name.

The name, rdtype, and 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.

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

replace_rdataset(self, name, replacement)

source code 

Replace an rdataset at name.

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

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

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

Parameters:
  • name (DNS.name.Name object or string) - the owner name
  • replacement (dns.rdataset.Rdataset) - the replacement rdataset

find_rrset(self, name, rdtype, covers=0)

source code 

Look for rdata with the specified name and type in the zone, and return an RRset encapsulating it.

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

This method is less efficient than the similar 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 find_rdataset instead.

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

Parameters:
  • name (DNS.name.Name object or string) - the owner name to look for
  • rdtype (int or string) - the rdata type desired
  • covers (int or string) - the covered type (defaults to None)
Returns: dns.rrset.RRset object
Raises:
  • KeyError - the node or rdata could not be found

get_rrset(self, name, rdtype, covers=0)

source code 

Look for rdata with the specified name and type in the zone, and return an RRset encapsulating it.

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

This method is less efficient than the similar 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 find_rdataset instead.

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

Parameters:
  • name (DNS.name.Name object or string) - the owner name to look for
  • rdtype (int or string) - the rdata type desired
  • covers (int or string) - the covered type (defaults to None)
Returns: dns.rrset.RRset object

iterate_rdatasets(self, rdtype=255, covers=0)

source code 

Return a generator which yields (name, rdataset) tuples for all rdatasets in the zone which have the specified rdtype and covers. If rdtype is dns.rdatatype.ANY, the default, then all rdatasets will be matched.

Parameters:
  • rdtype (int or string) - int or string
  • covers (int or string) - the covered type (defaults to None)

iterate_rdatas(self, rdtype=255, covers=0)

source code 

Return a generator which yields (name, ttl, rdata) tuples for all rdatas in the zone which have the specified rdtype and covers. If rdtype is dns.rdatatype.ANY, the default, then all rdatas will be matched.

Parameters:
  • rdtype (int or string) - int or string
  • covers (int or string) - the covered type (defaults to None)

to_file(self, f, sorted=True, relativize=True, nl=None)

source code 

Write a zone to a file.

Parameters:
  • f - file or string. If f is a string, it is treated as the name of a file to open.
  • 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.
  • relativize (bool) - if True, domain names in the output will be relativized to the zone's origin (if possible).
  • nl (string or None) - 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).

to_text(self, sorted=True, relativize=True, nl=None)

source code 

Return a zone's text as though it were written to a file.

Parameters:
  • 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.
  • relativize (bool) - if True, domain names in the output will be relativized to the zone's origin (if possible).
  • nl (string or None) - 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).

check_origin(self)

source code 

Do some simple checking of the zone's origin.

Raises: