def testImmutableNodes(self): z = dns.zone.from_text(example_text, 'example.', relativize=True, zone_factory=dns.versioned.Zone) node = z.find_node('@') with self.assertRaises(TypeError): node.find_rdataset(dns.rdataclass.IN, dns.rdatatype.RP, create=True) with self.assertRaises(TypeError): node.get_rdataset(dns.rdataclass.IN, dns.rdatatype.RP, create=True) with self.assertRaises(TypeError): node.delete_rdataset(dns.rdataclass.IN, dns.rdatatype.SOA) with self.assertRaises(TypeError): node.replace_rdataset(None)
def 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.rrset.RRset object """ name = self._validate_name(name) if isinstance(rdtype, (str, unicode)): rdtype = dns.rdatatype.from_text(rdtype) if isinstance(covers, (str, unicode)): covers = dns.rdatatype.from_text(covers) node = self.find_node(name, create) return node.find_rdataset(self.rdclass, rdtype, covers, create)
def 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.rrset.RRset object """ name = self._validate_name(name) if isinstance(rdtype, (str, unicode)): rdtype = dns.rdatatype.from_text(rdtype) if isinstance(covers, (str, unicode)): covers = dns.rdatatype.from_text(covers) node = self.find_node(name, create) return node.find_rdataset(self.rdclass, rdtype, covers, create)
def testNodeReplaceRdatasetConvertsRRsets(self): node = dns.node.Node() rrs = dns.rrset.from_text('foo', 300, 'in', 'a', '10.0.0.1') node.replace_rdataset(rrs) rds = node.find_rdataset(dns.rdataclass.IN, dns.rdatatype.A) self.assertEqual(rds, rrs) self.assertTrue(rds is not rrs) self.assertFalse(isinstance(rds, dns.rrset.RRset))
def testNodeFindRdataset3(self): z = dns.zone.from_text(example_text, "example.", relativize=True) node = z["@"] rds = node.find_rdataset(dns.rdataclass.IN, dns.rdatatype.RRSIG, dns.rdatatype.A, create=True) self.assertEqual(rds.rdclass, dns.rdataclass.IN) self.assertEqual(rds.rdtype, dns.rdatatype.RRSIG) self.assertEqual(rds.covers, dns.rdatatype.A)
def find_rdataset(self, name, rdtype, covers=dns.rdatatype.NONE, create=False): """Look for an rdataset with the specified name and type in the zone, and return an rdataset encapsulating it. 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. *name*: the name of the node to find. The value may be a ``dns.name.Name`` or a ``str``. If absolute, the name must be a subdomain of the zone's origin. If ``zone.relativize`` is ``True``, then the name will be relativized. *rdtype*, an ``int`` or ``str``, the rdata type desired. *covers*, an ``int`` or ``str`` or ``None``, the covered type. Usually this value is ``dns.rdatatype.NONE``, but if the rdtype is ``dns.rdatatype.SIG`` or ``dns.rdatatype.RRSIG``, then the covers value will be the rdata type the SIG/RRSIG covers. The library treats the SIG and RRSIG types as if they were a family of types, e.g. RRSIG(A), RRSIG(NS), RRSIG(SOA). This makes RRSIGs much easier to work with than if RRSIGs covering different rdata types were aggregated into a single RRSIG rdataset. *create*, a ``bool``. If true, the node will be created if it does not exist. Raises ``KeyError`` if the name is not known and create was not specified, or if the name was not a subdomain of the origin. Returns a ``dns.rdataset.Rdataset``. """ name = self._validate_name(name) if isinstance(rdtype, str): rdtype = dns.rdatatype.from_text(rdtype) if isinstance(covers, str): covers = dns.rdatatype.from_text(covers) node = self.find_node(name, create) return node.find_rdataset(self.rdclass, rdtype, covers, create)
def _find_key(keys, rrsig): value = keys.get(rrsig.signer) if value is None: return None if isinstance(value, dns.node.Node): try: rdataset = node.find_rdataset(dns.rdataclass.IN, dns.rdatatype.DNSKEY) except KeyError: return None else: rdataset = value for rdata in rdataset: if rdata.algorithm == rrsig.algorithm and \ key_id(rdata) == rrsig.key_tag: return rdata return None
def bad(): # type: () -> None z = dns.zone.from_text(example_text, 'example.', relativize=True) node = z['@'] node.find_rdataset(dns.rdataclass.IN, dns.rdatatype.LOC)
def testNodeFindRdataset1(self): # type: () -> None z = dns.zone.from_text(example_text, 'example.', relativize=True) node = z['@'] rds = node.find_rdataset(dns.rdataclass.IN, dns.rdatatype.SOA) exrds = dns.rdataset.from_text('IN', 'SOA', 300, 'foo bar 1 2 3 4 5') self.assertEqual(rds, exrds)
def testNodeFindRdataset1(self): # type: () -> None z = dns.zone.from_text(example_text, 'example.', relativize=True) node = z['@'] rds = node.find_rdataset(dns.rdataclass.IN, dns.rdatatype.SOA) exrds = dns.rdataset.from_text('IN', 'SOA', 300, 'foo bar 1 2 3 4 5') self.failUnless(rds == exrds)
def bad(): z = dns.zone.from_text(example_text, "example.", relativize=True) node = z["@"] node.find_rdataset(dns.rdataclass.IN, dns.rdatatype.LOC)
def testNodeFindRdataset1(self): z = dns.zone.from_text(example_text, "example.", relativize=True) node = z["@"] rds = node.find_rdataset(dns.rdataclass.IN, dns.rdatatype.SOA) exrds = dns.rdataset.from_text("IN", "SOA", 300, "foo bar 1 2 3 4 5") self.assertEqual(rds, exrds)