if isinstance(algorithm, str):
algorithm = DSDigest[algorithm.upper()]
except Exception:
- raise UnsupportedAlgorithm('unsupported algorithm "%s"' % algorithm)
+ raise UnsupportedAlgorithm(f'unsupported algorithm "{algorithm}"')
if validating:
check = policy.ok_to_validate_ds
else:
elif algorithm == DSDigest.SHA384:
dshash = hashlib.sha384()
else:
- raise UnsupportedAlgorithm('unsupported algorithm "%s"' % algorithm)
+ raise UnsupportedAlgorithm(f'unsupported algorithm "{algorithm}"')
if isinstance(name, str):
name = dns.name.from_text(name, origin)
if isinstance(algorithm, str):
algorithm = DSDigest[algorithm.upper()]
except Exception:
- raise UnsupportedAlgorithm('unsupported algorithm "%s"' % algorithm)
+ raise UnsupportedAlgorithm(f'unsupported algorithm "{algorithm}"')
_algorithms.add(algorithm)
if rdataset.rdtype == dns.rdatatype.CDS:
if cls:
return cls
raise UnsupportedAlgorithm(
- 'algorithm "%s" not supported by dnspython' % Algorithm.to_text(algorithm)
+ f'algorithm "{Algorithm.to_text(algorithm)}" not supported by dnspython'
)
if kwargs:
assert (
set(kwargs.keys()) == self.supp_kwargs
- ), "following set of keyword args is required: %s" % (self.supp_kwargs)
+ ), f"following set of keyword args is required: {self.supp_kwargs}"
return kwargs
def _fmt_kwargs(self, **kwargs):
elif c.isdigit():
cur += c
else:
- raise dns.exception.SyntaxError("Could not parse %s" % (c))
+ raise dns.exception.SyntaxError(f"Could not parse {c}")
if state == 0:
raise dns.exception.SyntaxError("no stop value specified")
s = io.StringIO()
s.write("id %d\n" % self.id)
- s.write("opcode %s\n" % dns.opcode.to_text(self.opcode()))
- s.write("rcode %s\n" % dns.rcode.to_text(self.rcode()))
- s.write("flags %s\n" % dns.flags.to_text(self.flags))
+ s.write(f"opcode {dns.opcode.to_text(self.opcode())}\n")
+ s.write(f"rcode {dns.rcode.to_text(self.rcode())}\n")
+ s.write(f"flags {dns.flags.to_text(self.flags)}\n")
if self.edns >= 0:
- s.write("edns %s\n" % self.edns)
+ s.write(f"edns {self.edns}\n")
if self.ednsflags != 0:
- s.write("eflags %s\n" % dns.flags.edns_to_text(self.ednsflags))
+ s.write(f"eflags {dns.flags.edns_to_text(self.ednsflags)}\n")
s.write("payload %d\n" % self.payload)
for opt in self.options:
- s.write("option %s\n" % opt.to_text())
+ s.write(f"option {opt.to_text()}\n")
for name, which in self._section_enum.__members__.items():
s.write(f";{name}\n")
for rrset in self.section_from_number(which):
else:
key = self.keyring
if key is None:
- raise UnknownTSIGKey("key '%s' unknown" % name)
+ raise UnknownTSIGKey(f"key '{name}' unknown")
self.message.keyring = key
self.message.tsig_ctx = dns.tsig.validate(
self.parser.wire,
return s[:100] + "..."
return s
- return "[%s]" % ", ".join("<%s>" % maybe_truncate(str(rr)) for rr in self)
+ return "[" + ", ".join(f"<{maybe_truncate(str(rr))}>" for rr in self) + "]"
def __repr__(self):
if self.covers == 0:
if self.subaddress:
return f'"{dns.rdata._escapify(self.address)}" "{dns.rdata._escapify(self.subaddress)}"'
else:
- return '"%s"' % dns.rdata._escapify(self.address)
+ return f'"{dns.rdata._escapify(self.address)}"'
@classmethod
def from_text(
exp = i - 1
break
if exp is None or exp < 0:
- raise dns.exception.SyntaxError("%s value out of bounds" % desc)
+ raise dns.exception.SyntaxError(f"{desc} value out of bounds")
return exp
def _decode_size(what, desc):
exponent = what & 0x0F
if exponent > 9:
- raise dns.exception.FormError("bad %s exponent" % desc)
+ raise dns.exception.FormError(f"bad {desc} exponent")
base = (what & 0xF0) >> 4
if base > 9:
- raise dns.exception.FormError("bad %s base" % desc)
+ raise dns.exception.FormError(f"bad {desc} base")
return base * pow(10, exponent)
dns.rdata._base64ify(self.key, 0),
)
if len(self.other) > 0:
- text += " %s" % (dns.rdata._base64ify(self.other, 0))
+ text += f" {dns.rdata._base64ify(self.other, 0)}"
return text
self.address = self._as_bytes(address, True, 255)
def to_text(self, origin=None, relativize=True, **kw):
- return '"%s"' % dns.rdata._escapify(self.address)
+ return f'"{dns.rdata._escapify(self.address)}"'
@classmethod
def from_text(
def to_text(self, origin=None, relativize=True, **kw):
domain = self.domain.choose_relativity(origin, relativize)
- return "%s %o" % (domain, self.address)
+ return f"{domain} {self.address:o}"
@classmethod
def from_text(
self.address = self._as_bytes(address)
def to_text(self, origin=None, relativize=True, **kw):
- return "0x%s" % binascii.hexlify(self.address).decode()
+ return f"0x{binascii.hexlify(self.address).decode()}"
@classmethod
def from_text(
self.eui = self._as_bytes(eui)
if len(self.eui) != self.byte_len:
raise dns.exception.FormError(
- "EUI%s rdata has to have %s bytes" % (self.byte_len * 8, self.byte_len)
+ f"EUI{self.byte_len * 8} rdata has to have {self.byte_len} bytes"
)
def to_text(self, origin=None, relativize=True, **kw):
text = tok.get_string()
if len(text) != cls.text_len:
raise dns.exception.SyntaxError(
- "Input text must have %s characters" % cls.text_len
+ f"Input text must have {cls.text_len} characters"
)
for i in range(2, cls.byte_len * 3 - 1, 3):
if text[i] != "-":
- raise dns.exception.SyntaxError("Dash expected at position %s" % i)
+ raise dns.exception.SyntaxError(f"Dash expected at position {i}")
text = text.replace("-", "")
try:
data = binascii.unhexlify(text.encode())
except (ValueError, TypeError) as ex:
- raise dns.exception.SyntaxError("Hex decoding error: %s" % str(ex))
+ raise dns.exception.SyntaxError(f"Hex decoding error: {str(ex)}")
return cls(rdclass, rdtype, data)
def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
"""The resolution lifetime expired."""
msg = "The resolution lifetime expired."
- fmt = "%s after {timeout:.3f} seconds: {errors}" % msg[:-1]
+ fmt = f"{msg[:-1]} after {{timeout:.3f}} seconds: {{errors}}"
supp_kwargs = {"timeout", "errors"}
# We do this as otherwise mypy complains about unexpected keyword argument
"""
msg = "All nameservers failed to answer the query."
- fmt = "%s {query}: {errors}" % msg[:-1]
+ fmt = f"{msg[:-1]} {{query}}: {{errors}}"
supp_kwargs = {"request", "errors"}
# We do this as otherwise mypy complains about unexpected keyword argument
self.add(item) # lgtm[py/init-calls-subclass]
def __repr__(self):
- return "dns.set.Set(%s)" % repr(list(self.items.keys())) # pragma: no cover
+ return f"dns.set.Set({repr(list(self.items.keys()))})" # pragma: no cover
def add(self, item):
"""Add an item to the set."""
if value < 0 or value > 65535:
if base == 8:
raise dns.exception.SyntaxError(
- "%o is not an octal unsigned 16-bit integer" % value
+ f"{value:o} is not an octal unsigned 16-bit integer"
)
else:
raise dns.exception.SyntaxError(
elif c == "s":
total += current
else:
- raise BadTTL("unknown unit '%s'" % c)
+ raise BadTTL(f"unknown unit '{c}'")
current = 0
need_digit = True
if not current == 0:
lm,
r"SYSTEM\CurrentControlSet\Control\Network"
r"\{4D36E972-E325-11CE-BFC1-08002BE10318}"
- r"\%s\Connection" % guid,
+ rf"\{guid}\Connection",
)
try:
raise ValueError # pragma: no cover
device_key = winreg.OpenKey(
- lm, r"SYSTEM\CurrentControlSet\Enum\%s" % pnp_id
+ lm, rf"SYSTEM\CurrentControlSet\Enum\{pnp_id}"
)
try:
"""A zone transfer response got a non-zero rcode."""
def __init__(self, rcode):
- message = "Zone transfer error: %s" % dns.rcode.to_text(rcode)
+ message = f"Zone transfer error: {dns.rcode.to_text(rcode)}"
super().__init__(message)
self.rcode = rcode
try:
rdtype = dns.rdatatype.from_text(token.value)
except Exception:
- raise dns.exception.SyntaxError("unknown rdatatype '%s'" % token.value)
+ raise dns.exception.SyntaxError(f"unknown rdatatype '{token.value}'")
try:
rd = dns.rdata.from_text(
width = int(width)
if sign not in ["+", "-"]:
- raise dns.exception.SyntaxError("invalid offset sign %s" % sign)
+ raise dns.exception.SyntaxError(f"invalid offset sign {sign}")
if base not in ["d", "o", "x", "X", "n", "N"]:
- raise dns.exception.SyntaxError("invalid type %s" % base)
+ raise dns.exception.SyntaxError(f"invalid type {base}")
return mod, sign, offset, width, base
if not token.is_identifier():
raise dns.exception.SyntaxError
except Exception:
- raise dns.exception.SyntaxError("unknown rdatatype '%s'" % token.value)
+ raise dns.exception.SyntaxError(f"unknown rdatatype '{token.value}'")
# rhs (required)
rhs = token.value
lzfindex = _format_index(lindex, lbase, lwidth)
rzfindex = _format_index(rindex, rbase, rwidth)
- name = lhs.replace("$%s" % (lmod), lzfindex)
- rdata = rhs.replace("$%s" % (rmod), rzfindex)
+ name = lhs.replace(f"${lmod}", lzfindex)
+ rdata = rhs.replace(f"${rmod}", rzfindex)
self.last_name = dns.name.from_text(
name, self.current_origin, self.tok.idna_codec
# helpful filename:line info.
(ty, va) = sys.exc_info()[:2]
raise dns.exception.SyntaxError(
- "caught exception %s: %s" % (str(ty), str(va))
+ f"caught exception {str(ty)}: {str(va)}"
)
self.txn.add(name, ttl, rd)
# isort
"I",
]
-lint.ignore = [
- "E501",
- "E741",
- "F401",
- "I001",
- "SIM102",
- "B904",
- "B011",
- "UP031",
-]
+lint.ignore = ["E501", "E741", "F401", "I001", "SIM102", "B904", "B011"]
lint.exclude = ["tests/*"]
[tool.isort]