import dns.wire
import dns.exception
+import dns.immutable
# fullcompare() result values
raise ValueError # pragma: no cover
+@dns.immutable.immutable
class Name:
"""A DNS name.
"""
labels = [_maybe_convert_to_binary(x) for x in labels]
- super().__setattr__('labels', tuple(labels))
+ self.labels = tuple(labels)
_validate_labels(self.labels)
- def __setattr__(self, name, value):
- # Names are immutable
- raise TypeError("object doesn't support attribute assignment")
-
- def __delattr__(self, name):
- # Names are immutable
- raise TypeError("object doesn't support attribute deletion")
-
def __copy__(self):
return Name(self.labels)
_constify = dns.immutable.constify
+@dns.immutable.immutable
class Rdata:
"""Base class for all DNS rdata types."""
*rdtype*, an ``int`` is the rdatatype of the Rdata.
"""
- object.__setattr__(self, 'rdclass', rdclass)
- object.__setattr__(self, 'rdtype', rdtype)
- object.__setattr__(self, 'rdcomment', None)
-
- def __setattr__(self, name, value):
- # Rdatas are immutable
- raise TypeError("object doesn't support attribute assignment")
-
- def __delattr__(self, name):
- # Rdatas are immutable
- raise TypeError("object doesn't support attribute deletion")
+ self.rdclass = rdclass
+ self.rdtype = rdtype
+ self.rdcomment = None
def _get_all_slots(self):
return itertools.chain.from_iterable(getattr(cls, '__slots__', [])
object.__setattr__(rd, 'rdcomment', rdcomment)
return rd
+ def as_value(self, value):
+ # This is the "additional type checking" placeholder that actually
+ # doesn't do any additional checking.
+ return value
+
class GenericRdata(Rdata):
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.mxbase
+import dns.immutable
+@dns.immutable.immutable
class AFSDB(dns.rdtypes.mxbase.UncompressedDowncasingMX):
"""AFSDB record"""
import struct
import dns.exception
+import dns.immutable
import dns.rdtypes.util
class Relay(dns.rdtypes.util.Gateway):
name = 'AMTRELAY relay'
+@dns.immutable.immutable
class AMTRELAY(dns.rdata.Rdata):
"""AMTRELAY record"""
relay_type, relay):
super().__init__(rdclass, rdtype)
Relay(relay_type, relay).check()
- object.__setattr__(self, 'precedence', precedence)
- object.__setattr__(self, 'discovery_optional', discovery_optional)
- object.__setattr__(self, 'relay_type', relay_type)
- object.__setattr__(self, 'relay', relay)
+ self.precedence = self.as_value(precedence)
+ self.discovery_optional = self.as_value(discovery_optional)
+ self.relay_type = self.as_value(relay_type)
+ self.relay = self.as_value(relay)
def to_text(self, origin=None, relativize=True, **kw):
relay = Relay(self.relay_type, self.relay).to_text(origin, relativize)
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.txtbase
+import dns.immutable
+@dns.immutable.immutable
class AVC(dns.rdtypes.txtbase.TXTBase):
"""AVC record"""
import struct
import dns.exception
+import dns.immutable
import dns.rdata
import dns.tokenizer
+@dns.immutable.immutable
class CAA(dns.rdata.Rdata):
"""CAA (Certification Authority Authorization) record"""
def __init__(self, rdclass, rdtype, flags, tag, value):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'flags', flags)
- object.__setattr__(self, 'tag', tag)
- object.__setattr__(self, 'value', value)
+ self.flags = self.as_value(flags)
+ self.tag = self.as_value(tag)
+ self.value = self.as_value(value)
def to_text(self, origin=None, relativize=True, **kw):
return '%u %s "%s"' % (self.flags,
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.dnskeybase
+import dns.immutable
# pylint: disable=unused-import
from dns.rdtypes.dnskeybase import SEP, REVOKE, ZONE # noqa: F401
# pylint: enable=unused-import
+@dns.immutable.immutable
class CDNSKEY(dns.rdtypes.dnskeybase.DNSKEYBase):
"""CDNSKEY record"""
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.dsbase
+import dns.immutable
+@dns.immutable.immutable
class CDS(dns.rdtypes.dsbase.DSBase):
"""CDS record"""
import base64
import dns.exception
+import dns.immutable
import dns.dnssec
import dns.rdata
import dns.tokenizer
return str(what)
+@dns.immutable.immutable
class CERT(dns.rdata.Rdata):
"""CERT record"""
def __init__(self, rdclass, rdtype, certificate_type, key_tag, algorithm,
certificate):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'certificate_type', certificate_type)
- object.__setattr__(self, 'key_tag', key_tag)
- object.__setattr__(self, 'algorithm', algorithm)
- object.__setattr__(self, 'certificate', certificate)
+ self.certificate_type = self.as_value(certificate_type)
+ self.key_tag = self.as_value(key_tag)
+ self.algorithm = self.as_value(algorithm)
+ self.certificate = self.as_value(certificate)
def to_text(self, origin=None, relativize=True, **kw):
certificate_type = _ctype_to_text(self.certificate_type)
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.nsbase
+import dns.immutable
+@dns.immutable.immutable
class CNAME(dns.rdtypes.nsbase.NSBase):
"""CNAME record
import struct
import dns.exception
+import dns.immutable
import dns.rdata
import dns.rdatatype
import dns.name
import dns.rdtypes.util
+@dns.immutable.immutable
class Bitmap(dns.rdtypes.util.Bitmap):
type_name = 'CSYNC'
+@dns.immutable.immutable
class CSYNC(dns.rdata.Rdata):
"""CSYNC record"""
def __init__(self, rdclass, rdtype, serial, flags, windows):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'serial', serial)
- object.__setattr__(self, 'flags', flags)
- object.__setattr__(self, 'windows', dns.rdata._constify(windows))
+ self.serial = self.as_value(serial)
+ self.flags = self.as_value(flags)
+ self.windows = self.as_value(dns.rdata._constify(windows))
def to_text(self, origin=None, relativize=True, **kw):
text = Bitmap(self.windows).to_text()
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.dsbase
+import dns.immutable
+@dns.immutable.immutable
class DLV(dns.rdtypes.dsbase.DSBase):
"""DLV record"""
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.nsbase
+import dns.immutable
+@dns.immutable.immutable
class DNAME(dns.rdtypes.nsbase.UncompressedNS):
"""DNAME record"""
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.dnskeybase
+import dns.immutable
# pylint: disable=unused-import
from dns.rdtypes.dnskeybase import SEP, REVOKE, ZONE # noqa: F401
# pylint: enable=unused-import
+@dns.immutable.immutable
class DNSKEY(dns.rdtypes.dnskeybase.DNSKEYBase):
"""DNSKEY record"""
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.dsbase
+import dns.immutable
+@dns.immutable.immutable
class DS(dns.rdtypes.dsbase.DSBase):
"""DS record"""
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.euibase
+import dns.immutable
+@dns.immutable.immutable
class EUI48(dns.rdtypes.euibase.EUIBase):
"""EUI48 record"""
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.euibase
+import dns.immutable
+@dns.immutable.immutable
class EUI64(dns.rdtypes.euibase.EUIBase):
"""EUI64 record"""
import struct
import dns.exception
+import dns.immutable
import dns.rdata
import dns.tokenizer
return value
+@dns.immutable.immutable
class GPOS(dns.rdata.Rdata):
"""GPOS record"""
_validate_float_string(latitude)
_validate_float_string(longitude)
_validate_float_string(altitude)
- object.__setattr__(self, 'latitude', latitude)
- object.__setattr__(self, 'longitude', longitude)
- object.__setattr__(self, 'altitude', altitude)
+ self.latitude = self.as_value(latitude)
+ self.longitude = self.as_value(longitude)
+ self.altitude = self.as_value(altitude)
flat = self.float_latitude
if flat < -90.0 or flat > 90.0:
raise dns.exception.FormError('bad latitude')
import struct
import dns.exception
+import dns.immutable
import dns.rdata
import dns.tokenizer
+@dns.immutable.immutable
class HINFO(dns.rdata.Rdata):
"""HINFO record"""
def __init__(self, rdclass, rdtype, cpu, os):
super().__init__(rdclass, rdtype)
if isinstance(cpu, str):
- object.__setattr__(self, 'cpu', cpu.encode())
+ self.cpu = self.as_value(cpu.encode())
else:
- object.__setattr__(self, 'cpu', cpu)
+ self.cpu = self.as_value(cpu)
if isinstance(os, str):
- object.__setattr__(self, 'os', os.encode())
+ self.os = self.as_value(os.encode())
else:
- object.__setattr__(self, 'os', os)
+ self.os = self.as_value(os)
def to_text(self, origin=None, relativize=True, **kw):
return '"{}" "{}"'.format(dns.rdata._escapify(self.cpu),
import binascii
import dns.exception
+import dns.immutable
import dns.rdata
import dns.rdatatype
+@dns.immutable.immutable
class HIP(dns.rdata.Rdata):
"""HIP record"""
def __init__(self, rdclass, rdtype, hit, algorithm, key, servers):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'hit', hit)
- object.__setattr__(self, 'algorithm', algorithm)
- object.__setattr__(self, 'key', key)
- object.__setattr__(self, 'servers', dns.rdata._constify(servers))
+ self.hit = self.as_value(hit)
+ self.algorithm = self.as_value(algorithm)
+ self.key = self.as_value(key)
+ self.servers = self.as_value(dns.rdata._constify(servers))
def to_text(self, origin=None, relativize=True, **kw):
hit = binascii.hexlify(self.hit).decode()
import struct
import dns.exception
+import dns.immutable
import dns.rdata
import dns.tokenizer
+@dns.immutable.immutable
class ISDN(dns.rdata.Rdata):
"""ISDN record"""
def __init__(self, rdclass, rdtype, address, subaddress):
super().__init__(rdclass, rdtype)
if isinstance(address, str):
- object.__setattr__(self, 'address', address.encode())
+ self.address = self.as_value(address.encode())
else:
- object.__setattr__(self, 'address', address)
+ self.address = self.as_value(address)
if isinstance(address, str):
- object.__setattr__(self, 'subaddress', subaddress.encode())
+ self.subaddress = self.as_value(subaddress.encode())
else:
- object.__setattr__(self, 'subaddress', subaddress)
+ self.subaddress = self.as_value(subaddress)
def to_text(self, origin=None, relativize=True, **kw):
if self.subaddress:
import struct
import dns.exception
+import dns.immutable
import dns.rdata
return base * pow(10, exponent)
+@dns.immutable.immutable
class LOC(dns.rdata.Rdata):
"""LOC record"""
latitude = float(latitude)
if isinstance(latitude, float):
latitude = _float_to_tuple(latitude)
- object.__setattr__(self, 'latitude', dns.rdata._constify(latitude))
+ self.latitude = self.as_value(dns.rdata._constify(latitude))
if isinstance(longitude, int):
longitude = float(longitude)
if isinstance(longitude, float):
longitude = _float_to_tuple(longitude)
- object.__setattr__(self, 'longitude', dns.rdata._constify(longitude))
- object.__setattr__(self, 'altitude', float(altitude))
- object.__setattr__(self, 'size', float(size))
- object.__setattr__(self, 'horizontal_precision', float(hprec))
- object.__setattr__(self, 'vertical_precision', float(vprec))
+ self.longitude = self.as_value(dns.rdata._constify(longitude))
+ self.altitude = self.as_value(float(altitude))
+ self.size = self.as_value(float(size))
+ self.horizontal_precision = self.as_value(float(hprec))
+ self.vertical_precision = self.as_value(float(vprec))
def to_text(self, origin=None, relativize=True, **kw):
if self.latitude[4] > 0:
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.mxbase
+import dns.immutable
+@dns.immutable.immutable
class MX(dns.rdtypes.mxbase.MXBase):
"""MX record"""
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.txtbase
+import dns.immutable
+@dns.immutable.immutable
class NINFO(dns.rdtypes.txtbase.TXTBase):
"""NINFO record"""
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.nsbase
+import dns.immutable
+@dns.immutable.immutable
class NS(dns.rdtypes.nsbase.NSBase):
"""NS record"""
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.exception
+import dns.immutable
import dns.rdata
import dns.rdatatype
import dns.name
import dns.rdtypes.util
+@dns.immutable.immutable
class Bitmap(dns.rdtypes.util.Bitmap):
type_name = 'NSEC'
+@dns.immutable.immutable
class NSEC(dns.rdata.Rdata):
"""NSEC record"""
def __init__(self, rdclass, rdtype, next, windows):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'next', next)
- object.__setattr__(self, 'windows', dns.rdata._constify(windows))
+ self.next = self.as_value(next)
+ self.windows = self.as_value(dns.rdata._constify(windows))
def to_text(self, origin=None, relativize=True, **kw):
next = self.next.choose_relativity(origin, relativize)
import struct
import dns.exception
+import dns.immutable
import dns.rdata
import dns.rdatatype
import dns.rdtypes.util
OPTOUT = 1
+@dns.immutable.immutable
class Bitmap(dns.rdtypes.util.Bitmap):
type_name = 'NSEC3'
+@dns.immutable.immutable
class NSEC3(dns.rdata.Rdata):
"""NSEC3 record"""
def __init__(self, rdclass, rdtype, algorithm, flags, iterations, salt,
next, windows):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'algorithm', algorithm)
- object.__setattr__(self, 'flags', flags)
- object.__setattr__(self, 'iterations', iterations)
+ self.algorithm = self.as_value(algorithm)
+ self.flags = self.as_value(flags)
+ self.iterations = self.as_value(iterations)
if isinstance(salt, str):
- object.__setattr__(self, 'salt', salt.encode())
+ self.salt = self.as_value(salt.encode())
else:
- object.__setattr__(self, 'salt', salt)
- object.__setattr__(self, 'next', next)
- object.__setattr__(self, 'windows', dns.rdata._constify(windows))
+ self.salt = self.as_value(salt)
+ self.next = self.as_value(next)
+ self.windows = self.as_value(dns.rdata._constify(windows))
def to_text(self, origin=None, relativize=True, **kw):
next = base64.b32encode(self.next).translate(
import binascii
import dns.exception
+import dns.immutable
import dns.rdata
+@dns.immutable.immutable
class NSEC3PARAM(dns.rdata.Rdata):
"""NSEC3PARAM record"""
def __init__(self, rdclass, rdtype, algorithm, flags, iterations, salt):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'algorithm', algorithm)
- object.__setattr__(self, 'flags', flags)
- object.__setattr__(self, 'iterations', iterations)
+ self.algorithm = self.as_value(algorithm)
+ self.flags = self.as_value(flags)
+ self.iterations = self.as_value(iterations)
if isinstance(salt, str):
- object.__setattr__(self, 'salt', salt.encode())
+ self.salt = self.as_value(salt.encode())
else:
- object.__setattr__(self, 'salt', salt)
+ self.salt = self.as_value(salt)
def to_text(self, origin=None, relativize=True, **kw):
if self.salt == b'':
import base64
import dns.exception
+import dns.immutable
import dns.rdata
import dns.tokenizer
+@dns.immutable.immutable
class OPENPGPKEY(dns.rdata.Rdata):
"""OPENPGPKEY record"""
def __init__(self, rdclass, rdtype, key):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'key', key)
+ self.key = self.as_value(key)
def to_text(self, origin=None, relativize=True, **kw):
return dns.rdata._base64ify(self.key)
import struct
import dns.edns
+import dns.immutable
import dns.exception
import dns.rdata
# We don't implement from_text, and that's ok.
# pylint: disable=abstract-method
+@dns.immutable.immutable
class OPT(dns.rdata.Rdata):
"""OPT record"""
"""
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'options', dns.rdata._constify(options))
+ self.options = self.as_value(dns.rdata._constify(options))
def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
for opt in self.options:
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.nsbase
+import dns.immutable
+@dns.immutable.immutable
class PTR(dns.rdtypes.nsbase.NSBase):
"""PTR record"""
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.exception
+import dns.immutable
import dns.rdata
import dns.name
+@dns.immutable.immutable
class RP(dns.rdata.Rdata):
"""RP record"""
def __init__(self, rdclass, rdtype, mbox, txt):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'mbox', mbox)
- object.__setattr__(self, 'txt', txt)
+ self.mbox = self.as_value(mbox)
+ self.txt = self.as_value(txt)
def to_text(self, origin=None, relativize=True, **kw):
mbox = self.mbox.choose_relativity(origin, relativize)
import time
import dns.dnssec
+import dns.immutable
import dns.exception
import dns.rdata
import dns.rdatatype
return time.strftime('%Y%m%d%H%M%S', time.gmtime(what))
+@dns.immutable.immutable
class RRSIG(dns.rdata.Rdata):
"""RRSIG record"""
original_ttl, expiration, inception, key_tag, signer,
signature):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'type_covered', type_covered)
- object.__setattr__(self, 'algorithm', algorithm)
- object.__setattr__(self, 'labels', labels)
- object.__setattr__(self, 'original_ttl', original_ttl)
- object.__setattr__(self, 'expiration', expiration)
- object.__setattr__(self, 'inception', inception)
- object.__setattr__(self, 'key_tag', key_tag)
- object.__setattr__(self, 'signer', signer)
- object.__setattr__(self, 'signature', signature)
+ self.type_covered = self.as_value(type_covered)
+ self.algorithm = self.as_value(algorithm)
+ self.labels = self.as_value(labels)
+ self.original_ttl = self.as_value(original_ttl)
+ self.expiration = self.as_value(expiration)
+ self.inception = self.as_value(inception)
+ self.key_tag = self.as_value(key_tag)
+ self.signer = self.as_value(signer)
+ self.signature = self.as_value(signature)
def covers(self):
return self.type_covered
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.mxbase
+import dns.immutable
+@dns.immutable.immutable
class RT(dns.rdtypes.mxbase.UncompressedDowncasingMX):
"""RT record"""
import struct
import dns.exception
+import dns.immutable
import dns.rdata
import dns.name
+@dns.immutable.immutable
class SOA(dns.rdata.Rdata):
"""SOA record"""
def __init__(self, rdclass, rdtype, mname, rname, serial, refresh, retry,
expire, minimum):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'mname', mname)
- object.__setattr__(self, 'rname', rname)
- object.__setattr__(self, 'serial', serial)
- object.__setattr__(self, 'refresh', refresh)
- object.__setattr__(self, 'retry', retry)
- object.__setattr__(self, 'expire', expire)
- object.__setattr__(self, 'minimum', minimum)
+ self.mname = self.as_value(mname)
+ self.rname = self.as_value(rname)
+ self.serial = self.as_value(serial)
+ self.refresh = self.as_value(refresh)
+ self.retry = self.as_value(retry)
+ self.expire = self.as_value(expire)
+ self.minimum = self.as_value(minimum)
def to_text(self, origin=None, relativize=True, **kw):
mname = self.mname.choose_relativity(origin, relativize)
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.txtbase
+import dns.immutable
+@dns.immutable.immutable
class SPF(dns.rdtypes.txtbase.TXTBase):
"""SPF record"""
import binascii
import dns.rdata
+import dns.immutable
import dns.rdatatype
+@dns.immutable.immutable
class SSHFP(dns.rdata.Rdata):
"""SSHFP record"""
def __init__(self, rdclass, rdtype, algorithm, fp_type,
fingerprint):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'algorithm', algorithm)
- object.__setattr__(self, 'fp_type', fp_type)
- object.__setattr__(self, 'fingerprint', fingerprint)
+ self.algorithm = self.as_value(algorithm)
+ self.fp_type = self.as_value(fp_type)
+ self.fingerprint = self.as_value(fingerprint)
def to_text(self, origin=None, relativize=True, **kw):
return '%d %d %s' % (self.algorithm,
import struct
import dns.dnssec
+import dns.immutable
import dns.exception
import dns.rdata
+@dns.immutable.immutable
class TKEY(dns.rdata.Rdata):
"""TKEY Record"""
def __init__(self, rdclass, rdtype, algorithm, inception, expiration,
mode, error, key, other=b''):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'algorithm', algorithm)
- object.__setattr__(self, 'inception', inception)
- object.__setattr__(self, 'expiration', expiration)
- object.__setattr__(self, 'mode', mode)
- object.__setattr__(self, 'error', error)
- object.__setattr__(self, 'key', dns.rdata._constify(key))
- object.__setattr__(self, 'other', dns.rdata._constify(other))
+ self.algorithm = self.as_value(algorithm)
+ self.inception = self.as_value(inception)
+ self.expiration = self.as_value(expiration)
+ self.mode = self.as_value(mode)
+ self.error = self.as_value(error)
+ self.key = self.as_value(dns.rdata._constify(key))
+ self.other = self.as_value(dns.rdata._constify(other))
def to_text(self, origin=None, relativize=True, **kw):
_algorithm = self.algorithm.choose_relativity(origin, relativize)
import binascii
import dns.rdata
+import dns.immutable
import dns.rdatatype
+@dns.immutable.immutable
class TLSA(dns.rdata.Rdata):
"""TLSA record"""
def __init__(self, rdclass, rdtype, usage, selector,
mtype, cert):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'usage', usage)
- object.__setattr__(self, 'selector', selector)
- object.__setattr__(self, 'mtype', mtype)
- object.__setattr__(self, 'cert', cert)
+ self.usage = self.as_value(usage)
+ self.selector = self.as_value(selector)
+ self.mtype = self.as_value(mtype)
+ self.cert = self.as_value(cert)
def to_text(self, origin=None, relativize=True, **kw):
return '%d %d %d %s' % (self.usage,
import struct
import dns.exception
+import dns.immutable
import dns.rdata
+@dns.immutable.immutable
class TSIG(dns.rdata.Rdata):
"""TSIG record"""
"""
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'algorithm', algorithm)
- object.__setattr__(self, 'time_signed', time_signed)
- object.__setattr__(self, 'fudge', fudge)
- object.__setattr__(self, 'mac', dns.rdata._constify(mac))
- object.__setattr__(self, 'original_id', original_id)
- object.__setattr__(self, 'error', error)
- object.__setattr__(self, 'other', dns.rdata._constify(other))
+ self.algorithm = self.as_value(algorithm)
+ self.time_signed = self.as_value(time_signed)
+ self.fudge = self.as_value(fudge)
+ self.mac = self.as_value(dns.rdata._constify(mac))
+ self.original_id = self.as_value(original_id)
+ self.error = self.as_value(error)
+ self.other = self.as_value(dns.rdata._constify(other))
def to_text(self, origin=None, relativize=True, **kw):
algorithm = self.algorithm.choose_relativity(origin, relativize)
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.txtbase
+import dns.immutable
+@dns.immutable.immutable
class TXT(dns.rdtypes.txtbase.TXTBase):
"""TXT record"""
import struct
import dns.exception
+import dns.immutable
import dns.rdata
import dns.name
+@dns.immutable.immutable
class URI(dns.rdata.Rdata):
"""URI record"""
def __init__(self, rdclass, rdtype, priority, weight, target):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'priority', priority)
- object.__setattr__(self, 'weight', weight)
+ self.priority = self.as_value(priority)
+ self.weight = self.as_value(weight)
if len(target) < 1:
raise dns.exception.SyntaxError("URI target cannot be empty")
if isinstance(target, str):
- object.__setattr__(self, 'target', target.encode())
+ self.target = self.as_value(target.encode())
else:
- object.__setattr__(self, 'target', target)
+ self.target = self.as_value(target)
def to_text(self, origin=None, relativize=True, **kw):
return '%d %d "%s"' % (self.priority, self.weight,
import struct
import dns.exception
+import dns.immutable
import dns.rdata
import dns.tokenizer
+@dns.immutable.immutable
class X25(dns.rdata.Rdata):
"""X25 record"""
def __init__(self, rdclass, rdtype, address):
super().__init__(rdclass, rdtype)
if isinstance(address, str):
- object.__setattr__(self, 'address', address.encode())
+ self.address = self.as_value(address.encode())
else:
- object.__setattr__(self, 'address', address)
+ self.address = self.as_value(address)
def to_text(self, origin=None, relativize=True, **kw):
return '"%s"' % dns.rdata._escapify(self.address)
import struct
import dns.rdtypes.mxbase
+import dns.immutable
+@dns.immutable.immutable
class A(dns.rdata.Rdata):
"""A record for Chaosnet"""
def __init__(self, rdclass, rdtype, domain, address):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'domain', domain)
- object.__setattr__(self, 'address', address)
+ self.domain = self.as_value(domain)
+ self.address = self.as_value(address)
def to_text(self, origin=None, relativize=True, **kw):
domain = self.domain.choose_relativity(origin, relativize)
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.exception
+import dns.immutable
import dns.ipv4
import dns.rdata
import dns.tokenizer
+@dns.immutable.immutable
class A(dns.rdata.Rdata):
"""A record."""
super().__init__(rdclass, rdtype)
# check that it's OK
dns.ipv4.inet_aton(address)
- object.__setattr__(self, 'address', address)
+ self.address = self.as_value(address)
def to_text(self, origin=None, relativize=True, **kw):
return self.address
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.exception
+import dns.immutable
import dns.ipv6
import dns.rdata
import dns.tokenizer
+@dns.immutable.immutable
class AAAA(dns.rdata.Rdata):
"""AAAA record."""
super().__init__(rdclass, rdtype)
# check that it's OK
dns.ipv6.inet_aton(address)
- object.__setattr__(self, 'address', address)
+ self.address = self.as_value(address)
def to_text(self, origin=None, relativize=True, **kw):
return self.address
import struct
import dns.exception
+import dns.immutable
import dns.ipv4
import dns.ipv6
import dns.rdata
import dns.tokenizer
+@dns.immutable.immutable
class APLItem:
"""An APL list item."""
file.write(address)
+@dns.immutable.immutable
class APL(dns.rdata.Rdata):
"""APL record."""
def __init__(self, rdclass, rdtype, items):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'items', dns.rdata._constify(items))
+ self.items = self.as_value(dns.rdata._constify(items))
def to_text(self, origin=None, relativize=True, **kw):
return ' '.join(map(str, self.items))
import base64
import dns.exception
+import dns.immutable
+@dns.immutable.immutable
class DHCID(dns.rdata.Rdata):
"""DHCID record"""
def __init__(self, rdclass, rdtype, data):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'data', data)
+ self.data = self.as_value(data)
def to_text(self, origin=None, relativize=True, **kw):
return dns.rdata._base64ify(self.data)
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
import dns.rdtypes.svcbbase
+import dns.immutable
+@dns.immutable.immutable
class HTTPS(dns.rdtypes.svcbbase.SVCBBase):
"""HTTPS record"""
import base64
import dns.exception
+import dns.immutable
import dns.rdtypes.util
class Gateway(dns.rdtypes.util.Gateway):
name = 'IPSECKEY gateway'
+@dns.immutable.immutable
class IPSECKEY(dns.rdata.Rdata):
"""IPSECKEY record"""
gateway, key):
super().__init__(rdclass, rdtype)
Gateway(gateway_type, gateway).check()
- object.__setattr__(self, 'precedence', precedence)
- object.__setattr__(self, 'gateway_type', gateway_type)
- object.__setattr__(self, 'algorithm', algorithm)
- object.__setattr__(self, 'gateway', gateway)
- object.__setattr__(self, 'key', key)
+ self.precedence = self.as_value(precedence)
+ self.gateway_type = self.as_value(gateway_type)
+ self.algorithm = self.as_value(algorithm)
+ self.gateway = self.as_value(gateway)
+ self.key = self.as_value(key)
def to_text(self, origin=None, relativize=True, **kw):
gateway = Gateway(self.gateway_type, self.gateway).to_text(origin,
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.mxbase
+import dns.immutable
+@dns.immutable.immutable
class KX(dns.rdtypes.mxbase.UncompressedDowncasingMX):
"""KX record"""
import struct
import dns.exception
+import dns.immutable
import dns.name
import dns.rdata
return value
+@dns.immutable.immutable
class NAPTR(dns.rdata.Rdata):
"""NAPTR record"""
def __init__(self, rdclass, rdtype, order, preference, flags, service,
regexp, replacement):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'flags', _sanitize(flags))
- object.__setattr__(self, 'service', _sanitize(service))
- object.__setattr__(self, 'regexp', _sanitize(regexp))
- object.__setattr__(self, 'order', order)
- object.__setattr__(self, 'preference', preference)
- object.__setattr__(self, 'replacement', replacement)
+ self.flags = self.as_value(_sanitize(flags))
+ self.service = self.as_value(_sanitize(service))
+ self.regexp = self.as_value(_sanitize(regexp))
+ self.order = self.as_value(order)
+ self.preference = self.as_value(preference)
+ self.replacement = self.as_value(replacement)
def to_text(self, origin=None, relativize=True, **kw):
replacement = self.replacement.choose_relativity(origin, relativize)
import binascii
import dns.exception
+import dns.immutable
import dns.rdata
import dns.tokenizer
+@dns.immutable.immutable
class NSAP(dns.rdata.Rdata):
"""NSAP record."""
def __init__(self, rdclass, rdtype, address):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'address', address)
+ self.address = self.as_value(address)
def to_text(self, origin=None, relativize=True, **kw):
return "0x%s" % binascii.hexlify(self.address).decode()
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.nsbase
+import dns.immutable
+@dns.immutable.immutable
class NSAP_PTR(dns.rdtypes.nsbase.UncompressedNS):
"""NSAP-PTR record"""
import struct
import dns.exception
+import dns.immutable
import dns.rdata
import dns.name
+@dns.immutable.immutable
class PX(dns.rdata.Rdata):
"""PX record."""
def __init__(self, rdclass, rdtype, preference, map822, mapx400):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'preference', preference)
- object.__setattr__(self, 'map822', map822)
- object.__setattr__(self, 'mapx400', mapx400)
+ self.preference = self.as_value(preference)
+ self.map822 = self.as_value(map822)
+ self.mapx400 = self.as_value(mapx400)
def to_text(self, origin=None, relativize=True, **kw):
map822 = self.map822.choose_relativity(origin, relativize)
import struct
import dns.exception
+import dns.immutable
import dns.rdata
import dns.name
+@dns.immutable.immutable
class SRV(dns.rdata.Rdata):
"""SRV record"""
def __init__(self, rdclass, rdtype, priority, weight, port, target):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'priority', priority)
- object.__setattr__(self, 'weight', weight)
- object.__setattr__(self, 'port', port)
- object.__setattr__(self, 'target', target)
+ self.priority = self.as_value(priority)
+ self.weight = self.as_value(weight)
+ self.port = self.as_value(port)
+ self.target = self.as_value(target)
def to_text(self, origin=None, relativize=True, **kw):
target = self.target.choose_relativity(origin, relativize)
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
import dns.rdtypes.svcbbase
+import dns.immutable
+@dns.immutable.immutable
class SVCB(dns.rdtypes.svcbbase.SVCBBase):
"""SVCB record"""
import struct
import dns.ipv4
+import dns.immutable
import dns.rdata
_proto_tcp = socket.getprotobyname('tcp')
_proto_udp = socket.getprotobyname('udp')
+@dns.immutable.immutable
class WKS(dns.rdata.Rdata):
"""WKS record"""
def __init__(self, rdclass, rdtype, address, protocol, bitmap):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'address', address)
- object.__setattr__(self, 'protocol', protocol)
- object.__setattr__(self, 'bitmap', dns.rdata._constify(bitmap))
+ self.address = self.as_value(address)
+ self.protocol = self.as_value(protocol)
+ self.bitmap = self.as_value(dns.rdata._constify(bitmap))
def to_text(self, origin=None, relativize=True, **kw):
bits = []
import struct
import dns.exception
+import dns.immutable
import dns.dnssec
import dns.rdata
ZONE = 0x0100
+@dns.immutable.immutable
class DNSKEYBase(dns.rdata.Rdata):
"""Base class for rdata that is like a DNSKEY record"""
def __init__(self, rdclass, rdtype, flags, protocol, algorithm, key):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'flags', flags)
- object.__setattr__(self, 'protocol', protocol)
- object.__setattr__(self, 'algorithm', algorithm)
- object.__setattr__(self, 'key', key)
+ self.flags = self.as_value(flags)
+ self.protocol = self.as_value(protocol)
+ self.algorithm = self.as_value(algorithm)
+ self.key = self.as_value(key)
def to_text(self, origin=None, relativize=True, **kw):
return '%d %d %d %s' % (self.flags, self.protocol, self.algorithm,
import binascii
import dns.dnssec
+import dns.immutable
import dns.rdata
import dns.rdatatype
+@dns.immutable.immutable
class DSBase(dns.rdata.Rdata):
"""Base class for rdata that is like a DS record"""
def __init__(self, rdclass, rdtype, key_tag, algorithm, digest_type,
digest):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'key_tag', key_tag)
- object.__setattr__(self, 'algorithm', algorithm)
- object.__setattr__(self, 'digest_type', digest_type)
- object.__setattr__(self, 'digest', digest)
+ self.key_tag = self.as_value(key_tag)
+ self.algorithm = self.as_value(algorithm)
+ self.digest_type = self.as_value(digest_type)
+ self.digest = self.as_value(digest)
def to_text(self, origin=None, relativize=True, **kw):
return '%d %d %d %s' % (self.key_tag, self.algorithm,
import binascii
import dns.rdata
+import dns.immutable
+@dns.immutable.immutable
class EUIBase(dns.rdata.Rdata):
"""EUIxx record"""
if len(eui) != self.byte_len:
raise dns.exception.FormError('EUI%s rdata has to have %s bytes'
% (self.byte_len * 8, self.byte_len))
- object.__setattr__(self, 'eui', eui)
+ self.eui = self.as_value(eui)
def to_text(self, origin=None, relativize=True, **kw):
return dns.rdata._hexify(self.eui, chunksize=2).replace(' ', '-')
import struct
import dns.exception
+import dns.immutable
import dns.rdata
import dns.name
+@dns.immutable.immutable
class MXBase(dns.rdata.Rdata):
"""Base class for rdata that is like an MX record."""
def __init__(self, rdclass, rdtype, preference, exchange):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'preference', preference)
- object.__setattr__(self, 'exchange', exchange)
+ self.preference = self.as_value(preference)
+ self.exchange = self.as_value(exchange)
def to_text(self, origin=None, relativize=True, **kw):
exchange = self.exchange.choose_relativity(origin, relativize)
return cls(rdclass, rdtype, preference, exchange)
+@dns.immutable.immutable
class UncompressedMX(MXBase):
"""Base class for rdata that is like an MX record, but whose name
super()._to_wire(file, None, origin, False)
+@dns.immutable.immutable
class UncompressedDowncasingMX(MXBase):
"""Base class for rdata that is like an MX record, but whose name
"""NS-like base classes."""
import dns.exception
+import dns.immutable
import dns.rdata
import dns.name
+@dns.immutable.immutable
class NSBase(dns.rdata.Rdata):
"""Base class for rdata that is like an NS record."""
def __init__(self, rdclass, rdtype, target):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'target', target)
+ self.target = self.as_value(target)
def to_text(self, origin=None, relativize=True, **kw):
target = self.target.choose_relativity(origin, relativize)
return cls(rdclass, rdtype, target)
+@dns.immutable.immutable
class UncompressedNS(NSBase):
"""Base class for rdata that is like an NS record, but whose name
import struct
import dns.enum
+import dns.immutable
import dns.exception
import dns.immutable
import dns.ipv4
return items[0]
+@dns.immutable.immutable
class Param:
"""Abstract base class for SVCB parameters"""
- def __setattr__(self, name, value):
- # Params are immutable
- raise TypeError("object doesn't support attribute assignment")
-
- def __delattr__(self, name):
- # Params are immutable
- raise TypeError("object doesn't support attribute deletion")
-
@classmethod
def emptiness(cls):
return Emptiness.NEVER
+ def as_value(self, value):
+ # This is the "additional type checking" placeholder that actually
+ # doesn't do any additional checking.
+ return value
+
+
+@dns.immutable.immutable
class GenericParam(Param):
"""Generic SVCB parameter
"""
def __init__(self, value):
- object.__setattr__(self, 'value', value)
+ self.value = self.as_value(value)
@classmethod
def emptiness(cls):
file.write(self.value)
+@dns.immutable.immutable
class MandatoryParam(Param):
def __init__(self, keys):
# check for duplicates
if k == ParamKey.MANDATORY:
raise ValueError('listed the mandatory key as mandatory')
keys = dns.immutable.constify(keys)
- object.__setattr__(self, 'keys', keys)
+ self.keys = self.as_value(keys)
@classmethod
def from_value(cls, value):
for key in self.keys:
file.write(struct.pack('!H', key))
+
+@dns.immutable.immutable
class ALPNParam(Param):
def __init__(self, ids):
for id in ids:
raise dns.exception.FormError('empty ALPN')
if len(id) > 255:
raise ValueError('ALPN id too long')
- object.__setattr__(self, 'ids', dns.immutable.constify(ids))
+ self.ids = self.as_value(dns.immutable.constify(ids))
@classmethod
def from_value(cls, value):
file.write(struct.pack('!B', len(id)))
file.write(id)
+
+@dns.immutable.immutable
class NoDefaultALPNParam(Param):
# We don't ever expect to instantiate this class, but we need
# a from_value() and a from_wire_parser(), so we just return None
raise NotImplementedError # pragma: no cover
+@dns.immutable.immutable
class PortParam(Param):
def __init__(self, port):
if port < 0 or port > 65535:
raise ValueError('port out-of-range')
- object.__setattr__(self, 'port', port)
+ self.port = self.as_value(port)
@classmethod
def from_value(cls, value):
file.write(struct.pack('!H', self.port))
+@dns.immutable.immutable
class IPv4HintParam(Param):
def __init__(self, addresses):
for address in addresses:
# check validity
dns.ipv4.inet_aton(address)
- object.__setattr__(self, 'addresses', dns.immutable.constify(addresses))
+ self.addresses = self.as_value(dns.immutable.constify(addresses))
@classmethod
def from_value(cls, value):
file.write(dns.ipv4.inet_aton(address))
+@dns.immutable.immutable
class IPv6HintParam(Param):
def __init__(self, addresses):
for address in addresses:
# check validity
dns.ipv6.inet_aton(address)
- object.__setattr__(self, 'addresses', dns.immutable.constify(addresses))
+ self.addresses = self.as_value(dns.immutable.constify(addresses))
@classmethod
def from_value(cls, value):
file.write(dns.ipv6.inet_aton(address))
+@dns.immutable.immutable
class ECHConfigParam(Param):
def __init__(self, echconfig):
- object.__setattr__(self, 'echconfig', echconfig)
+ self.echconfig = self.as_value(echconfig)
@classmethod
def from_value(cls, value):
params[key] = value
+@dns.immutable.immutable
class SVCBBase(dns.rdata.Rdata):
"""Base class for SVCB-like records"""
def __init__(self, rdclass, rdtype, priority, target, params):
super().__init__(rdclass, rdtype)
- object.__setattr__(self, 'priority', priority)
- object.__setattr__(self, 'target', target)
- object.__setattr__(self, 'params', dns.immutable.constify(params))
+ self.priority = self.as_value(priority)
+ self.target = self.as_value(target)
+ self.params = self.as_value(dns.immutable.constify(params))
# Make sure any paramater listed as mandatory is present in the
# record.
mandatory = params.get(ParamKey.MANDATORY)
import struct
import dns.exception
+import dns.immutable
import dns.rdata
import dns.tokenizer
+@dns.immutable.immutable
class TXTBase(dns.rdata.Rdata):
"""Base class for rdata that is like a TXT record (see RFC 1035)."""
else:
string = dns.rdata._constify(string)
encoded_strings.append(string)
- object.__setattr__(self, 'strings', tuple(encoded_strings))
+ self.strings = self.as_value(tuple(encoded_strings))
def to_text(self, origin=None, relativize=True, **kw):
txt = ''