Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dns/edns.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def to_wire(self, file: Optional[Any] = None) -> Optional[bytes]:
return self.data

def to_text(self) -> str:
return "Generic %d" % self.otype
return f"Generic {self.otype}"

def to_generic(self) -> "GenericOption":
return self
Expand Down
2 changes: 1 addition & 1 deletion dns/ipv4.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def inet_ntoa(address: bytes) -> str:

if len(address) != 4:
raise dns.exception.SyntaxError
return "%u.%u.%u.%u" % (address[0], address[1], address[2], address[3])
return f"{address[0]}.{address[1]}.{address[2]}.{address[3]}"


def inet_aton(text: Union[str, bytes]) -> bytes:
Expand Down
4 changes: 2 additions & 2 deletions dns/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ def to_text(
"""

s = io.StringIO()
s.write("id %d\n" % self.id)
s.write(f"id {self.id}\n")
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(f"edns {self.edns}\n")
if self.ednsflags != 0:
s.write(f"eflags {dns.flags.edns_to_text(self.ednsflags)}\n")
s.write("payload %d\n" % self.payload)
s.write(f"payload {self.payload}\n")
for opt in self.options:
s.write(f"option {opt.to_text()}\n")
for name, which in self._section_enum.__members__.items():
Expand Down
4 changes: 2 additions & 2 deletions dns/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _escapify(label: Union[bytes, str]) -> str:
elif c > 0x20 and c < 0x7F:
text += chr(c)
else:
text += "\\%03d" % c
text += f"\\{c:03d}"
return text

# Unicode label mode. Escape only special characters and values < 0x20
Expand All @@ -167,7 +167,7 @@ def _escapify(label: Union[bytes, str]) -> str:
if uc in _escaped_text:
text += "\\" + uc
elif uc <= "\x20":
text += "\\%03d" % ord(uc)
text += f"\\{ord(uc):03d}"
else:
text += uc
return text
Expand Down
2 changes: 1 addition & 1 deletion dns/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ def __getattr__(self, _):
rrset = q.find_rrset(
q.authority, zone, dns.rdataclass.IN, dns.rdatatype.SOA, create=True
)
soa = dns.rdata.from_text("IN", "SOA", ". . %u 0 0 0 0" % serial)
soa = dns.rdata.from_text("IN", "SOA", f". . {serial} 0 0 0 0")
rrset.add(soa, 0)
if keyring is not None:
q.use_tsig(keyring, keyname, algorithm=keyalgorithm)
Expand Down
4 changes: 2 additions & 2 deletions dns/rdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _escapify(qstring):
elif c >= 0x20 and c < 0x7F:
text += chr(c)
else:
text += "\\%03d" % c
text += f"\\{c:03d}"
return text


Expand Down Expand Up @@ -619,7 +619,7 @@ def to_text(
relativize: bool = True,
**kw: Dict[str, Any],
) -> str:
return r"\# %d " % len(self.data) + _hexify(self.data, **kw) # pyright: ignore
return rf"\# {len(self.data)} " + _hexify(self.data, **kw) # pyright: ignore

@classmethod
def from_text(
Expand Down
15 changes: 5 additions & 10 deletions dns/rdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,11 @@ def to_text(
if rd.rdcomment:
extra = f" ;{rd.rdcomment}"
s.write(
"%s%s%d %s %s %s%s\n"
% (
ntext,
pad,
self.ttl,
dns.rdataclass.to_text(rdclass),
dns.rdatatype.to_text(self.rdtype),
rd.to_text(origin=origin, relativize=relativize, **kw),
extra,
)
f"{ntext}{pad}{self.ttl} "
f"{dns.rdataclass.to_text(rdclass)} "
f"{dns.rdatatype.to_text(self.rdtype)} "
f"{rd.to_text(origin=origin, relativize=relativize, **kw)}"
f"{extra}\n"
)
#
# We strip off the final \n for the caller's convenience in printing
Expand Down
7 changes: 2 additions & 5 deletions dns/rdtypes/ANY/AMTRELAY.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ def __init__(

def to_text(self, origin=None, relativize=True, **kw):
relay = Relay(self.relay_type, self.relay).to_text(origin, relativize)
return "%d %d %d %s" % (
self.precedence,
self.discovery_optional,
self.relay_type,
relay,
return (
f"{self.precedence} {self.discovery_optional:d} {self.relay_type} {relay}"
)

@classmethod
Expand Down
6 changes: 1 addition & 5 deletions dns/rdtypes/ANY/CAA.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ def __init__(self, rdclass, rdtype, flags, tag, value):
self.value = self._as_bytes(value)

def to_text(self, origin=None, relativize=True, **kw):
return '%u %s "%s"' % (
self.flags,
dns.rdata._escapify(self.tag),
dns.rdata._escapify(self.value),
)
return f'{self.flags} {dns.rdata._escapify(self.tag)} "{dns.rdata._escapify(self.value)}"'

@classmethod
def from_text(
Expand Down
9 changes: 3 additions & 6 deletions dns/rdtypes/ANY/CERT.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,9 @@ def __init__(

def to_text(self, origin=None, relativize=True, **kw):
certificate_type = _ctype_to_text(self.certificate_type)
return "%s %d %s %s" % (
certificate_type,
self.key_tag,
dns.dnssectypes.Algorithm.to_text(self.algorithm),
dns.rdata._base64ify(self.certificate, **kw), # pyright: ignore
)
algorithm = dns.dnssectypes.Algorithm.to_text(self.algorithm)
certificate = dns.rdata._base64ify(self.certificate, **kw) # pyright: ignore
return f"{certificate_type} {self.key_tag} {algorithm} {certificate}"

@classmethod
def from_text(
Expand Down
2 changes: 1 addition & 1 deletion dns/rdtypes/ANY/CSYNC.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, rdclass, rdtype, serial, flags, windows):

def to_text(self, origin=None, relativize=True, **kw):
text = Bitmap(self.windows).to_text()
return "%d %d%s" % (self.serial, self.flags, text)
return f"{self.serial} {self.flags}{text}"

@classmethod
def from_text(
Expand Down
2 changes: 1 addition & 1 deletion dns/rdtypes/ANY/HIP.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def to_text(self, origin=None, relativize=True, **kw):
servers.append(server.choose_relativity(origin, relativize))
if len(servers) > 0:
text += " " + " ".join(x.to_unicode() for x in servers)
return "%u %s %s%s" % (self.algorithm, hit, key, text)
return f"{self.algorithm} {hit} {key}{text}"

@classmethod
def from_text(
Expand Down
18 changes: 6 additions & 12 deletions dns/rdtypes/ANY/LOC.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,12 @@ def to_text(self, origin=None, relativize=True, **kw):
long_hemisphere = "E"
else:
long_hemisphere = "W"
text = "%d %d %d.%03d %s %d %d %d.%03d %s %0.2fm" % (
self.latitude[0],
self.latitude[1],
self.latitude[2],
self.latitude[3],
lat_hemisphere,
self.longitude[0],
self.longitude[1],
self.longitude[2],
self.longitude[3],
long_hemisphere,
self.altitude / 100.0,
text = (
f"{self.latitude[0]} {self.latitude[1]} "
f"{self.latitude[2]}.{self.latitude[3]:03d} {lat_hemisphere} "
f"{self.longitude[0]} {self.longitude[1]} "
f"{self.longitude[2]}.{self.longitude[3]:03d} {long_hemisphere} "
f"{(self.altitude / 100.0):0.2f}m"
)

# do not print default values
Expand Down
2 changes: 1 addition & 1 deletion dns/rdtypes/ANY/LP.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, rdclass, rdtype, preference, fqdn):

def to_text(self, origin=None, relativize=True, **kw):
fqdn = self.fqdn.choose_relativity(origin, relativize)
return "%d %s" % (self.preference, fqdn)
return f"{self.preference} {fqdn}"

@classmethod
def from_text(
Expand Down
9 changes: 1 addition & 8 deletions dns/rdtypes/ANY/NSEC3.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,7 @@ def to_text(self, origin=None, relativize=True, **kw):
else:
salt = binascii.hexlify(self.salt).decode()
text = Bitmap(self.windows).to_text()
return "%u %u %u %s %s%s" % (
self.algorithm,
self.flags,
self.iterations,
salt,
next,
text,
)
return f"{self.algorithm} {self.flags} {self.iterations} {salt} {next}{text}"

@classmethod
def from_text(
Expand Down
2 changes: 1 addition & 1 deletion dns/rdtypes/ANY/NSEC3PARAM.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def to_text(self, origin=None, relativize=True, **kw):
salt = "-"
else:
salt = binascii.hexlify(self.salt).decode()
return "%u %u %u %s" % (self.algorithm, self.flags, self.iterations, salt)
return f"{self.algorithm} {self.flags} {self.iterations} {salt}"

@classmethod
def from_text(
Expand Down
18 changes: 8 additions & 10 deletions dns/rdtypes/ANY/RRSIG.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,14 @@ def covers(self):
return self.type_covered

def to_text(self, origin=None, relativize=True, **kw):
return "%s %d %d %d %s %s %d %s %s" % (
dns.rdatatype.to_text(self.type_covered),
self.algorithm,
self.labels,
self.original_ttl,
posixtime_to_sigtime(self.expiration),
posixtime_to_sigtime(self.inception),
self.key_tag,
self.signer.choose_relativity(origin, relativize),
dns.rdata._base64ify(self.signature, **kw), # pyright: ignore
return (
f"{dns.rdatatype.to_text(self.type_covered)} "
f"{self.algorithm} {self.labels} {self.original_ttl} "
f"{posixtime_to_sigtime(self.expiration)} "
f"{posixtime_to_sigtime(self.inception)} "
f"{self.key_tag} "
f"{self.signer.choose_relativity(origin, relativize)} "
f"{dns.rdata._base64ify(self.signature, **kw)}" # pyright: ignore
)

@classmethod
Expand Down
10 changes: 1 addition & 9 deletions dns/rdtypes/ANY/SOA.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,7 @@ def __init__(
def to_text(self, origin=None, relativize=True, **kw):
mname = self.mname.choose_relativity(origin, relativize)
rname = self.rname.choose_relativity(origin, relativize)
return "%s %s %d %d %d %d %d" % (
mname,
rname,
self.serial,
self.refresh,
self.retry,
self.expire,
self.minimum,
)
return f"{mname} {rname} {self.serial} {self.refresh} {self.retry} {self.expire} {self.minimum}"

@classmethod
def from_text(
Expand Down
9 changes: 3 additions & 6 deletions dns/rdtypes/ANY/SSHFP.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ def __init__(self, rdclass, rdtype, algorithm, fp_type, fingerprint):
def to_text(self, origin=None, relativize=True, **kw):
kw = kw.copy()
chunksize = kw.pop("chunksize", 128)
return "%d %d %s" % (
self.algorithm,
self.fp_type,
dns.rdata._hexify(
self.fingerprint, chunksize=chunksize, **kw # pyright: ignore
),
fingerprint = dns.rdata._hexify(
self.fingerprint, chunksize=chunksize, **kw # pyright: ignore
)
return f"{self.algorithm} {self.fp_type} {fingerprint}"

@classmethod
def from_text(
Expand Down
15 changes: 4 additions & 11 deletions dns/rdtypes/ANY/TKEY.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,11 @@ def __init__(

def to_text(self, origin=None, relativize=True, **kw):
_algorithm = self.algorithm.choose_relativity(origin, relativize)
text = "%s %u %u %u %u %s" % (
str(_algorithm),
self.inception,
self.expiration,
self.mode,
self.error,
dns.rdata._base64ify(self.key, 0),
)
key = dns.rdata._base64ify(self.key, 0)
other = ""
if len(self.other) > 0:
text += f" {dns.rdata._base64ify(self.other, 0)}"

return text
other = " " + dns.rdata._base64ify(self.other, 0)
return f"{_algorithm} {self.inception} {self.expiration} {self.mode} {self.error} {key}{other}"

@classmethod
def from_text(
Expand Down
2 changes: 1 addition & 1 deletion dns/rdtypes/ANY/URI.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, rdclass, rdtype, priority, weight, target):
raise dns.exception.SyntaxError("URI target cannot be empty")

def to_text(self, origin=None, relativize=True, **kw):
return '%d %d "%s"' % (self.priority, self.weight, self.target.decode())
return f'{self.priority} {self.weight} "{self.target.decode()}"'

@classmethod
def from_text(
Expand Down
10 changes: 3 additions & 7 deletions dns/rdtypes/ANY/ZONEMD.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@ def __init__(self, rdclass, rdtype, serial, scheme, hash_algorithm, digest):
def to_text(self, origin=None, relativize=True, **kw):
kw = kw.copy()
chunksize = kw.pop("chunksize", 128)
return "%d %d %d %s" % (
self.serial,
self.scheme,
self.hash_algorithm,
dns.rdata._hexify(
self.digest, chunksize=chunksize, **kw # pyright: ignore
),
digest = dns.rdata._hexify(
self.digest, chunksize=chunksize, **kw # pyright: ignore
)
return f"{self.serial} {self.scheme} {self.hash_algorithm} {digest}"

@classmethod
def from_text(
Expand Down
4 changes: 2 additions & 2 deletions dns/rdtypes/IN/APL.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def __init__(self, family, negation, address, prefix):

def __str__(self):
if self.negation:
return "!%d:%s/%s" % (self.family, self.address, self.prefix)
return f"!{self.family}:{self.address}/{self.prefix}"
else:
return "%d:%s/%s" % (self.family, self.address, self.prefix)
return f"{self.family}:{self.address}/{self.prefix}"

def to_wire(self, file):
if self.family == 1:
Expand Down
9 changes: 2 additions & 7 deletions dns/rdtypes/IN/IPSECKEY.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,8 @@ def __init__(

def to_text(self, origin=None, relativize=True, **kw):
gateway = Gateway(self.gateway_type, self.gateway).to_text(origin, relativize)
return "%d %d %d %s %s" % (
self.precedence,
self.gateway_type,
self.algorithm,
gateway,
dns.rdata._base64ify(self.key, **kw), # pyright: ignore
)
key = dns.rdata._base64ify(self.key, **kw) # pyright: ignore
return f"{self.precedence} {self.gateway_type} {self.algorithm} {gateway} {key}"

@classmethod
def from_text(
Expand Down
13 changes: 6 additions & 7 deletions dns/rdtypes/IN/NAPTR.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ def __init__(

def to_text(self, origin=None, relativize=True, **kw):
replacement = self.replacement.choose_relativity(origin, relativize)
return '%d %d "%s" "%s" "%s" %s' % (
self.order,
self.preference,
dns.rdata._escapify(self.flags),
dns.rdata._escapify(self.service),
dns.rdata._escapify(self.regexp),
replacement,
return (
f"{self.order} {self.preference} "
f'"{dns.rdata._escapify(self.flags)}" '
f'"{dns.rdata._escapify(self.service)}" '
f'"{dns.rdata._escapify(self.regexp)}" '
f"{replacement}"
)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion dns/rdtypes/IN/PX.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, rdclass, rdtype, preference, map822, mapx400):
def to_text(self, origin=None, relativize=True, **kw):
map822 = self.map822.choose_relativity(origin, relativize)
mapx400 = self.mapx400.choose_relativity(origin, relativize)
return "%d %s %s" % (self.preference, map822, mapx400)
return f"{self.preference} {map822} {mapx400}"

@classmethod
def from_text(
Expand Down
2 changes: 1 addition & 1 deletion dns/rdtypes/IN/SRV.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, rdclass, rdtype, priority, weight, port, target):

def to_text(self, origin=None, relativize=True, **kw):
target = self.target.choose_relativity(origin, relativize)
return "%d %d %d %s" % (self.priority, self.weight, self.port, target)
return f"{self.priority} {self.weight} {self.port} {target}"

@classmethod
def from_text(
Expand Down
Loading