Ejemplo n.º 1
0
def zone_for_name(name, rdclass=dnspython.rdataclass.IN, tcp=False, resolver=None):
    """Find the name of the zone which contains the specified name.

    @param name: the query name
    @type name: absolute dnspython.name.Name object or string
    @param rdclass: The query class
    @type rdclass: int
    @param tcp: use TCP to make the query (default is False).
    @type tcp: bool
    @param resolver: the resolver to use
    @type resolver: dnspython.resolver.Resolver object or None
    @rtype: dnspython.name.Name"""

    if isinstance(name, (str, unicode)):
        name = dnspython.name.from_text(name, dnspython.name.root)
    if resolver is None:
        resolver = get_default_resolver()
    if not name.is_absolute():
        raise NotAbsolute, name
    while 1:
        try:
            answer = resolver.query(name, dnspython.rdatatype.SOA, rdclass, tcp)
            return name
        except (dnspython.resolver.NXDOMAIN, dnspython.resolver.NoAnswer):
            try:
                name = name.parent()
            except dnspython.name.NoParent:
                raise NoRootSOA
Ejemplo n.º 2
0
 def _validate_name(self, name):
     if isinstance(name, (str, unicode)):
         name = dnspython.name.from_text(name, None)
     elif not isinstance(name, dnspython.name.Name):
         raise KeyError, "name parameter must be convertable to a DNS name"
     if name.is_absolute():
         if not name.is_subdomain(self.origin):
             raise KeyError, "name parameter must be a subdomain of the zone origin"
         if self.relativize:
             name = name.relativize(self.origin)
     return name