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

Type Zone

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.
Method Summary
  __init__(self, origin, rdclass, relativize)
Initialize a zone object.
  __contains__(self, other)
  __delitem__(self, key)
bool __eq__(self, other)
Two zones are equal if they have the same origin, class, and nodes.
  __getitem__(self, key)
  __iter__(self)
bool __ne__(self, other)
Are two zones not equal?
  __setitem__(self, key, value)
  check_origin(self)
Do some simple checking of the zone's origin.
  delete_node(self, name)
Delete the specified node if it exists.
  delete_rdataset(self, name, rdtype, covers)
Delete the rdataset matching rdtype and covers, if it exists at the node specified by name.
  find_node(self, name, create)
Find a node in the zone, possibly creating it.
dns.rrset.RRset object find_rdataset(self, name, rdtype, covers, create)
Look for rdata with the specified name and type in the zone, and return an rdataset encapsulating it.
dns.rrset.RRset object find_rrset(self, name, rdtype, covers)
Look for rdata with the specified name and type in the zone, and return an RRset encapsulating it.
  get(self, key)
  get_node(self, name, create)
Get a node in the zone, possibly creating it.
dns.rrset.RRset object get_rdataset(self, name, rdtype, covers, create)
Look for rdata with the specified name and type in the zone, and return an rdataset encapsulating it.
dns.rrset.RRset object get_rrset(self, name, rdtype, covers)
Look for rdata with the specified name and type in the zone, and return an RRset encapsulating it.
  items(self)
  iterate_rdatas(self, rdtype, covers)
Return a generator which yields (name, ttl, rdata) tuples for all rdatas in the zone which have the specified rdtype and covers.
  iterate_rdatasets(self, rdtype, covers)
Return a generator which yields (name, rdataset) tuples for all rdatasets in the zone which have the specified rdtype and covers.
  iteritems(self)
  iterkeys(self)
  itervalues(self)
  keys(self)
  replace_rdataset(self, name, replacement)
Replace an rdataset at name.
  to_file(self, f, sorted, relativize, nl)
Write a zone to a file.
  values(self)
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Instance Variable Summary
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?

Class Variable Summary
list __slots__ = ['rdclass', 'origin', 'nodes', 'relativize']
class or callable node_factory = dns.node.Node

Method Details

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

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

__eq__(self, other)
(Equality operator)

Two zones are equal if they have the same origin, class, and nodes.
Returns:
bool

__ne__(self, other)

Are two zones not equal?
Returns:
bool

check_origin(self)

Do some simple checking of the zone's origin.
Raises:
dns.zone.NoSOA - there is no SOA RR
dns.zone.NoNS - there is no NS RRset
KeyError - there is no origin node

delete_node(self, name)

Delete the specified node if it exists.

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

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

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 - the owner name to look for
           (type=DNS.name.Name object or string)
rdtype - the rdata type desired
           (type=int or string)
covers - the covered type (defaults to None)
           (type=int or string)

find_node(self, name, create=False)

Find a node in the zone, possibly creating it.
Parameters:
name - the name of the node to find
           (type=dns.name.Name object or string)
create - should the node be created if it doesn't exist?
           (type=bool)
Raises:
KeyError - the name is not known and create was not specified. @rtype dns.node.Node 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.

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 - the owner name to look for
           (type=DNS.name.Name object or string)
rdtype - the rdata type desired
           (type=int or string)
covers - the covered type (defaults to None)
           (type=int or string)
create - should the node and rdataset be created if they do not exist?
           (type=bool)
Returns:
dns.rrset.RRset object
Raises:
KeyError - the node or rdata could not be found

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.

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 - the owner name to look for
           (type=DNS.name.Name object or string)
rdtype - the rdata type desired
           (type=int or string)
covers - the covered type (defaults to None)
           (type=int or string)
Returns:
dns.rrset.RRset object
Raises:
KeyError - the node or rdata could not be found

get_node(self, name, create=False)

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 - the name of the node to find
           (type=dns.name.Name object or string)
create - should the node be created if it doesn't exist?
           (type=bool @rtype dns.node.Node 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.

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 - the owner name to look for
           (type=DNS.name.Name object or string)
rdtype - the rdata type desired
           (type=int or string)
covers - the covered type (defaults to None)
           (type=int or string)
create - should the node and rdataset be created if they do not exist?
           (type=bool)
Returns:
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.

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 - the owner name to look for
           (type=DNS.name.Name object or string)
rdtype - the rdata type desired
           (type=int or string)
covers - the covered type (defaults to None)
           (type=int or string)
Returns:
dns.rrset.RRset object

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. If rdtype is dns.rdatatype.ANY, the default, then all rdatas will be matched.
Parameters:
rdtype - int or string
           (type=int or string)
covers - the covered type (defaults to None)
           (type=int or string)

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. If rdtype is dns.rdatatype.ANY, the default, then all rdatasets will be matched.
Parameters:
rdtype - int or string
           (type=int or string)
covers - the covered type (defaults to None)
           (type=int or string)

replace_rdataset(self, name, replacement)

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 - the owner name
           (type=DNS.name.Name object or string)
replacement - the replacement rdataset
           (type=dns.rdataset.Rdataset)

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

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

Instance Variable Details

nodes

A dictionary mapping the names of nodes in the zone to the nodes themselves.
Type:
dict
Value:
<member 'nodes' of 'Zone' objects>                                     

origin

The origin of the zone.
Type:
dns.name.Name object
Value:
<member 'origin' of 'Zone' objects>                                    

rdclass

The zone's rdata class; the default is class IN.
Type:
int
Value:
<member 'rdclass' of 'Zone' objects>                                   

relativize

should names in the zone be relativized?
Type:
bool
Value:
<member 'relativize' of 'Zone' objects>                                

Class Variable Details

__slots__

Type:
list
Value:
['rdclass', 'origin', 'nodes', 'relativize']                           

Generated by Epydoc 2.1 on Fri Jun 2 14:38:18 2006 http://epydoc.sf.net