def zone_for_name(name, rdclass=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 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: resolver.Resolver object or None @rtype: name.Name""" if isinstance(name, (str, unicode)): name = name.from_text(name, 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, rdatatype.SOA, rdclass, tcp) if answer.rrset.name == name: return name # otherwise we were CNAMEd or DNAMEd and need to look higher except (resolver.NXDOMAIN, resolver.NoAnswer): pass try: name = name.parent() except name.NoParent: raise NoRootSOA
def _validate_name(self, name): if isinstance(name, (str, unicode)): name = name.from_text(name, None) elif not isinstance(name, 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
def _validate_name(self, name): if isinstance(name, (str, unicode)): name = name.from_text(name, None) elif not isinstance(name, 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