# kwargs if present, and the current value otherwise.
args = (kwargs.get(key, getattr(self, key)) for key in parameters)
- # Create and return the new object.
- return self.__class__(*args)
+ # Create, validate, and return the new object.
+ #
+ # Note that if we make constructors do validation in the future,
+ # this validation can go away.
+ rd = self.__class__(*args)
+ dns.rdata.from_text(rd.rdclass, rd.rdtype, rd.to_text())
+ return rd
class GenericRdata(Rdata):
import io
import unittest
+import dns.exception
import dns.name
import dns.rdata
import dns.rdataclass
with self.assertRaises(AttributeError):
mx.replace(invalid_parameter=1)
+ def test_invalid_replace(self):
+ a1 = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, "1.2.3.4")
+ def bad():
+ a1.replace(address="bogus")
+ self.assertRaises(dns.exception.SyntaxError, bad)
+
def test_to_generic(self):
a = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, "1.2.3.4")
self.assertEqual(str(a.to_generic()), r'\# 4 01020304')