# cannot make any mistakes (e.g. omissions, cut-and-paste errors) that
# would cause the mapping not to be true inverse.
-_algorithm_by_value = dict((y, x) for x, y in _algorithm_by_text.items())
+_algorithm_by_value = {y: x for x, y in _algorithm_by_text.items()}
def algorithm_from_text(text):
self.addrdata = self.addrdata[:-1] + last
def to_text(self):
- return "ECS %s/%s scope/%s" % (self.address, self.srclen,
- self.scopelen)
+ return "ECS {}/{} scope/{}".format(self.address, self.srclen,
+ self.scopelen)
def to_wire(self, file):
file.write(struct.pack('!H', self.family))
class Timeout(DNSException):
"""The DNS operation timed out."""
- supp_kwargs = set(['timeout'])
+ supp_kwargs = {'timeout'}
fmt = "The DNS operation timed out after {timeout} seconds"
# cannot make any mistakes (e.g. omissions, cut-and-paste errors) that
# would cause the mappings not to be true inverses.
-_by_value = dict((y, x) for x, y in _by_text.items())
+_by_value = {y: x for x, y in _by_text.items()}
-_edns_by_value = dict((y, x) for x, y in _edns_by_text.items())
+_edns_by_value = {y: x for x, y in _edns_by_text.items()}
def _order_flags(table):
m = _v4_ending.match(text)
if not m is None:
b = bytearray(dns.ipv4.inet_aton(m.group(2)))
- text = (u"%s:%02x%02x:%02x%02x" % (m.group(1).decode(), b[0], b[1],
- b[2], b[3])).encode()
+ text = (u"{}:{:02x}{:02x}:{:02x}{:02x}".format(m.group(1).decode(),
+ b[0], b[1], b[2],
+ b[3])).encode()
#
# Try to turn '::<whatever>' into ':<whatever>'; if no match try to
# turn '<whatever>::' into '<whatever>:'
class IDNAException(dns.exception.DNSException):
"""IDNA processing raised an exception."""
- supp_kwargs = set(['idna_exception'])
+ supp_kwargs = {'idna_exception'}
fmt = "IDNA processing exception: {idna_exception}"
# cannot make any mistakes (e.g. omissions, cut-and-paste errors) that
# would cause the mapping not to be true inverse.
-_by_value = dict((y, x) for x, y in _by_text.items())
+_by_value = {y: x for x, y in _by_text.items()}
class UnknownOpcode(dns.exception.DNSException):
# cannot make any mistakes (e.g. omissions, cut-and-paste errors) that
# would cause the mapping not to be a true inverse.
-_by_value = dict((y, x) for x, y in _by_text.items())
+_by_value = {y: x for x, y in _by_text.items()}
class UnknownRcode(dns.exception.DNSException):
class RdatatypeExists(dns.exception.DNSException):
"""DNS rdatatype already exists."""
- supp_kwargs = set(['rdclass', 'rdtype'])
+ supp_kwargs = {'rdclass', 'rdtype'}
fmt = "The rdata type with class {rdclass} and rdtype {rdtype} " + \
"already exists."
# cannot make any mistakes (e.g. omissions, cut-and-paste errors) that
# would cause the mapping not to be true inverse.
-_by_value = dict((y, x) for x, y in _by_text.items())
+_by_value = {y: x for x, y in _by_text.items()}
# Now that we've built the inverse map, we can add class aliases to
# the _by_text mapping.
# some dynamic updates, so we don't need to print out the TTL
# (which is meaningless anyway).
#
- s.write(u'%s%s%s %s\n' % (ntext, pad,
- dns.rdataclass.to_text(rdclass),
- dns.rdatatype.to_text(self.rdtype)))
+ s.write(u'{}{}{} {}\n'.format(ntext, pad,
+ dns.rdataclass.to_text(rdclass),
+ dns.rdatatype.to_text(self.rdtype)))
else:
for rd in self:
s.write(u'%s%s%d %s %s %s\n' %
# cannot make any mistakes (e.g. omissions, cut-and-paste errors) that
# would cause the mapping not to be true inverse.
-_by_value = dict((y, x) for x, y in _by_text.items())
+_by_value = {y: x for x, y in _by_text.items()}
_metatypes = {
OPT: True
self.altitude = altitude
def to_text(self, origin=None, relativize=True, **kw):
- return '%s %s %s' % (self.latitude.decode(),
+ return '{} {} {}'.format(self.latitude.decode(),
self.longitude.decode(),
self.altitude.decode())
self.os = os
def to_text(self, origin=None, relativize=True, **kw):
- return '"%s" "%s"' % (dns.rdata._escapify(self.cpu),
- dns.rdata._escapify(self.os))
+ return '"{}" "{}"'.format(dns.rdata._escapify(self.cpu),
+ dns.rdata._escapify(self.os))
@classmethod
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
def to_text(self, origin=None, relativize=True, **kw):
if self.subaddress:
- return '"%s" "%s"' % (dns.rdata._escapify(self.address),
+ return '"{}" "{}"'.format(dns.rdata._escapify(self.address),
dns.rdata._escapify(self.subaddress))
else:
return '"%s"' % dns.rdata._escapify(self.address)
if self.size != _default_size or \
self.horizontal_precision != _default_hprec or \
self.vertical_precision != _default_vprec:
- text += " %0.2fm %0.2fm %0.2fm" % (
+ text += " {:0.2f}m {:0.2f}m {:0.2f}m".format(
self.size / 100.0, self.horizontal_precision / 100.0,
self.vertical_precision / 100.0
)
bits.append(dns.rdatatype.to_text(window * 256 +
i * 8 + j))
text += (' ' + ' '.join(bits))
- return '%s%s' % (next, text)
+ return '{}{}'.format(next, text)
@classmethod
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
def to_text(self, origin=None, relativize=True, **kw):
mbox = self.mbox.choose_relativity(origin, relativize)
txt = self.txt.choose_relativity(origin, relativize)
- return "%s %s" % (str(mbox), str(txt))
+ return "{} {}".format(str(mbox), str(txt))
@classmethod
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
# We construct the inverse mapping programmatically to ensure that we
# cannot make any mistakes (e.g. omissions, cut-and-paste errors) that
# would cause the mapping not to be true inverse.
-_flag_by_value = dict((y, x) for x, y in _flag_by_text.items())
+_flag_by_value = {y: x for x, y in _flag_by_text.items()}
def flags_to_text_set(flags):
txt = ''
prefix = ''
for s in self.strings:
- txt += '%s"%s"' % (prefix, dns.rdata._escapify(s))
+ txt += '{}"{}"'.format(prefix, dns.rdata._escapify(s))
prefix = ' '
return txt
class NXDOMAIN(dns.exception.DNSException):
"""The DNS query name does not exist."""
- supp_kwargs = set(['qnames', 'responses'])
+ supp_kwargs = {'qnames', 'responses'}
fmt = None # we have our own __str__ implementation
def _check_kwargs(self, qnames, responses=None):
else:
msg = 'The DNS query name does not exist'
qnames = ', '.join(map(str, qnames))
- return "%s: %s" % (msg, qnames)
+ return "{}: {}".format(msg, qnames)
def canonical_name(self):
if not 'qnames' in self.kwargs:
"""The DNS response does not contain an answer to the question."""
fmt = 'The DNS response does not contain an answer ' + \
'to the question: {query}'
- supp_kwargs = set(['response'])
+ supp_kwargs = {'response'}
def _fmt_kwargs(self, **kwargs):
return super(NoAnswer, self)._fmt_kwargs(
msg = "All nameservers failed to answer the query."
fmt = "%s {query}: {errors}" % msg[:-1]
- supp_kwargs = set(['request', 'errors'])
+ supp_kwargs = {'request', 'errors'}
def _fmt_kwargs(self, **kwargs):
srv_msgs = []
for err in kwargs['errors']:
- srv_msgs.append('Server %s %s port %s answered %s' % (err[0],
+ srv_msgs.append('Server {} {} port {} answered {}'.format(err[0],
'TCP' if err[1] else 'UDP', err[2], err[3]))
return super(NoNameservers, self)._fmt_kwargs(
query=kwargs['request'].question, errors='; '.join(srv_msgs))
# helpful filename:line info.
(ty, va) = sys.exc_info()[:2]
raise dns.exception.SyntaxError(
- "caught exception %s: %s" % (str(ty), str(va)))
+ "caught exception {}: {}".format(str(ty), str(va)))
if not self.default_ttl_known and isinstance(rd, dns.rdtypes.ANY.SOA.SOA):
# The pre-RFC2308 and pre-BIND9 behavior inherits the zone default
Given 2 filenames and a list of changes from diff_zones, produce diff-like
output. If ignore_ttl is True, TTL-only changes are not displayed"""
- ret = "--- %s\n+++ %s\n" % (oldf, newf)
+ ret = "--- {}\n+++ {}\n".format(oldf, newf)
for name, old, new in changes:
ret += "@ %s\n" % name
if not old:
else:
if len(args) == 3:
filename, oldr, newr = args
- oldn = "%s:%s" % (oldr, filename)
- newn = "%s:%s" % (newr, filename)
+ oldn = "{}:{}".format(oldr, filename)
+ newn = "{}:{}".format(newr, filename)
else:
filename, oldr = args
newr = None
- oldn = "%s:%s" % (oldr, filename)
+ oldn = "{}:{}".format(oldr, filename)
newn = filename
old, new = None, None
oldz, newz = None, None
if opts.use_bzr:
old = _open(["bzr", "cat", "-r" + oldr, filename],
- "Unable to retrieve revision %s of %s" % (oldr, filename))
+ "Unable to retrieve revision {} of {}".format(oldr, filename))
if newr is not None:
new = _open(["bzr", "cat", "-r" + newr, filename],
- "Unable to retrieve revision %s of %s" % (newr, filename))
+ "Unable to retrieve revision {} of {}".format(newr, filename))
elif opts.use_git:
old = _open(["git", "show", oldn],
- "Unable to retrieve revision %s of %s" % (oldr, filename))
+ "Unable to retrieve revision {} of {}".format(oldr, filename))
if newr is not None:
new = _open(["git", "show", newn],
- "Unable to retrieve revision %s of %s" % (newr, filename))
+ "Unable to retrieve revision {} of {}".format(newr, filename))
elif opts.use_rcs:
old = _open(["co", "-q", "-p", "-r" + oldr, filename],
- "Unable to retrieve revision %s of %s" % (oldr, filename))
+ "Unable to retrieve revision {} of {}".format(oldr, filename))
if newr is not None:
new = _open(["co", "-q", "-p", "-r" + newr, filename],
- "Unable to retrieve revision %s of %s" % (newr, filename))
+ "Unable to retrieve revision {} of {}".format(newr, filename))
if not opts.use_vc:
old = _open(oldn, "Unable to open %s" % oldn)
if not opts.use_vc or newr is None:
'packages' : ['dns', 'dns.rdtypes', 'dns.rdtypes.IN', 'dns.rdtypes.ANY'],
'package_data' : {'dns': ['py.typed']},
'download_url' : \
- 'http://www.dnspython.org/kits/%s/dnspython-%s.tar.gz' % (version, version),
+ 'http://www.dnspython.org/kits/{}/dnspython-{}.tar.gz'.format(version, version),
'classifiers' : [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
class FormatedError(DNSException):
fmt = "Custom format: {parameter}"
- supp_kwargs = set(['parameter'])
+ supp_kwargs = {'parameter'}
class ExceptionTestCase(unittest.TestCase):
good_f = 0
from_flags = dns.rdtypes.ANY.DNSKEY.flags_to_text_set(good_f)
self.failUnless(from_flags == good_s,
- '"%s" != "%s"' % (from_flags, good_s))
+ '"{}" != "{}"'.format(from_flags, good_s))
from_set = dns.rdtypes.ANY.DNSKEY.flags_from_text_set(good_s)
self.failUnless(from_set == good_f,
- '"0x%x" != "0x%x"' % (from_set, good_f))
+ '"0x{:x}" != "0x{:x}"'.format(from_set, good_f))
def testFlagsAll(self): # type: () -> None
'''Test that all defined flags are recognized.'''
- good_s = set(['SEP', 'REVOKE', 'ZONE'])
+ good_s = {'SEP', 'REVOKE', 'ZONE'}
good_f = 0x181
from_flags = dns.rdtypes.ANY.DNSKEY.flags_to_text_set(good_f)
self.failUnless(from_flags == good_s,
- '"%s" != "%s"' % (from_flags, good_s))
+ '"{}" != "{}"'.format(from_flags, good_s))
from_text = dns.rdtypes.ANY.DNSKEY.flags_from_text_set(good_s)
self.failUnless(from_text == good_f,
- '"0x%x" != "0x%x"' % (from_text, good_f))
+ '"0x{:x}" != "0x{:x}"'.format(from_text, good_f))
def testFlagsUnknownToText(self): # type: () -> None
'''Test that undefined flags are returned in hexadecimal notation.'''
- unk_s = set(['0x8000'])
+ unk_s = {'0x8000'}
flags_s = dns.rdtypes.ANY.DNSKEY.flags_to_text_set(0x8000)
- self.failUnless(flags_s == unk_s, '"%s" != "%s"' % (flags_s, unk_s))
+ self.failUnless(flags_s == unk_s, '"{}" != "{}"'.format(flags_s, unk_s))
def testFlagsUnknownToFlags(self): # type: () -> None
'''Test that conversion from undefined mnemonic raises error.'''
def testFlagsRRToText(self): # type: () -> None
'''Test that RR method returns correct flags.'''
rr = dns.rrset.from_text('foo', 300, 'IN', 'DNSKEY', '257 3 8 KEY=')[0]
- rr_s = set(['ZONE', 'SEP'])
+ rr_s = {'ZONE', 'SEP'}
flags_s = rr.flags_to_text_set()
- self.failUnless(flags_s == rr_s, '"%s" != "%s"' % (flags_s, rr_s))
+ self.failUnless(flags_s == rr_s, '"{}" != "{}"'.format(flags_s, rr_s))
if __name__ == '__main__':
r2 = dns.rrset.from_text('FOO', 600, 'in', 'loc',
'49 11 42.400 N 16 36 29.600 E 227.64m '
'1.00m 10000.00m 10.00m')
- self.failUnless(r1 == r2, '"%s" != "%s"' % (r1, r2))
+ self.failUnless(r1 == r2, '"{}" != "{}"'.format(r1, r2))
def testEqual2(self):
'''Test default values for size, horizontal and vertical precision.'''
(16, 36, 29, 600, 1),
22764.0, # centimeters
100.0, 1000000.00, 1000.0) # centimeters
- self.failUnless(r1 == r2, '"%s" != "%s"' % (r1, r2))
+ self.failUnless(r1 == r2, '"{}" != "{}"'.format(r1, r2))
def testEqual3(self):
'''Test size, horizontal and vertical precision parsers: 100 cm == 1 m.
r2 = dns.rrset.from_text('FOO', 600, 'in', 'loc',
'49 11 42.400 N 16 36 29.600 E 227.64m '
'2.00m 10.00m 2.00m')[0]
- self.failUnless(r1 == r2, '"%s" != "%s"' % (r1, r2))
+ self.failUnless(r1 == r2, '"{}" != "{}"'.format(r1, r2))
def testEqual4(self):
'''Test size, horizontal and vertical precision parsers without unit.
r2 = dns.rrset.from_text('FOO', 600, 'in', 'loc',
'49 11 42.400 N 16 36 29.600 E 227.64 '
'2 10 2')[0] # meters without explicit unit
- self.failUnless(r1 == r2, '"%s" != "%s"' % (r1, r2))
+ self.failUnless(r1 == r2, '"{}" != "{}"'.format(r1, r2))
if __name__ == '__main__':
unittest.main()