From: Bob Halley Date: Wed, 24 Jul 2024 01:45:32 +0000 (-0700) Subject: automated format to f-string conversion + black X-Git-Tag: v2.7.0rc1~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ba2afa1a35235c7c037ee632396865409477e59;p=thirdparty%2Fdnspython.git automated format to f-string conversion + black --- diff --git a/dns/asyncquery.py b/dns/asyncquery.py index f7d4df44..717f43b4 100644 --- a/dns/asyncquery.py +++ b/dns/asyncquery.py @@ -554,13 +554,15 @@ async def https( af = None if af is not None and dns.inet.is_address(where): if af == socket.AF_INET: - url = "https://{}:{}{}".format(where, port, path) + url = f"https://{where}:{port}{path}" elif af == socket.AF_INET6: - url = "https://[{}]:{}{}".format(where, port, path) + url = f"https://[{where}]:{port}{path}" else: url = where - if http_version == HTTPVersion.H3 or (http_version == HTTPVersion.DEFAULT and not have_doh): + if http_version == HTTPVersion.H3 or ( + http_version == HTTPVersion.DEFAULT and not have_doh + ): if bootstrap_address is None: parsed = urllib.parse.urlparse(url) resolver = _maybe_get_resolver(resolver) @@ -621,9 +623,7 @@ async def https( if client: cm: contextlib.AbstractAsyncContextManager = NullContext(client) else: - cm = httpx.AsyncClient( - http1=h1, http2=h2, verify=verify, transport=transport - ) + cm = httpx.AsyncClient(http1=h1, http2=h2, verify=verify, transport=transport) async with cm as the_client: # see https://tools.ietf.org/html/rfc8484#section-4.1.1 for DoH @@ -649,10 +649,8 @@ async def https( # status codes if response.status_code < 200 or response.status_code > 299: raise ValueError( - "{} responded with status code {}" - "\nResponse body: {!r}".format( - where, response.status_code, response.content - ) + f"{where} responded with status code {response.status_code}" + f"\nResponse body: {response.content!r}" ) r = dns.message.from_wire( response.content, diff --git a/dns/edns.py b/dns/edns.py index af90827a..cbb7c443 100644 --- a/dns/edns.py +++ b/dns/edns.py @@ -222,7 +222,7 @@ class ECSOption(Option): # lgtm[py/missing-equals] self.addrdata = self.addrdata[:-1] + last def to_text(self) -> str: - return "ECS {}/{} scope/{}".format(self.address, self.srclen, self.scopelen) + return f"ECS {self.address}/{self.srclen} scope/{self.scopelen}" @staticmethod def from_text(text: str) -> Option: @@ -255,10 +255,10 @@ class ECSOption(Option): # lgtm[py/missing-equals] ecs_text = tokens[0] elif len(tokens) == 2: if tokens[0] != optional_prefix: - raise ValueError('could not parse ECS from "{}"'.format(text)) + raise ValueError(f'could not parse ECS from "{text}"') ecs_text = tokens[1] else: - raise ValueError('could not parse ECS from "{}"'.format(text)) + raise ValueError(f'could not parse ECS from "{text}"') n_slashes = ecs_text.count("/") if n_slashes == 1: address, tsrclen = ecs_text.split("/") @@ -266,18 +266,16 @@ class ECSOption(Option): # lgtm[py/missing-equals] elif n_slashes == 2: address, tsrclen, tscope = ecs_text.split("/") else: - raise ValueError('could not parse ECS from "{}"'.format(text)) + raise ValueError(f'could not parse ECS from "{text}"') try: scope = int(tscope) except ValueError: - raise ValueError( - "invalid scope " + '"{}": scope must be an integer'.format(tscope) - ) + raise ValueError("invalid scope " + f'"{tscope}": scope must be an integer') try: srclen = int(tsrclen) except ValueError: raise ValueError( - "invalid srclen " + '"{}": srclen must be an integer'.format(tsrclen) + "invalid srclen " + f'"{tsrclen}": srclen must be an integer' ) return ECSOption(address, srclen, scope) diff --git a/dns/ipv6.py b/dns/ipv6.py index 44a10639..4dd1d1ca 100644 --- a/dns/ipv6.py +++ b/dns/ipv6.py @@ -143,9 +143,7 @@ def inet_aton(text: Union[str, bytes], ignore_scope: bool = False) -> bytes: if m is not None: b = dns.ipv4.inet_aton(m.group(2)) btext = ( - "{}:{:02x}{:02x}:{:02x}{:02x}".format( - m.group(1).decode(), b[0], b[1], b[2], b[3] - ) + f"{m.group(1).decode()}:{b[0]:02x}{b[1]:02x}:{b[2]:02x}{b[3]:02x}" ).encode() # # Try to turn '::' into ':'; if no match try to diff --git a/dns/query.py b/dns/query.py index 8f8f97cd..050aeca4 100644 --- a/dns/query.py +++ b/dns/query.py @@ -443,13 +443,15 @@ def https( ) if af is not None and dns.inet.is_address(where): if af == socket.AF_INET: - url = "https://{}:{}{}".format(where, port, path) + url = f"https://{where}:{port}{path}" elif af == socket.AF_INET6: - url = "https://[{}]:{}{}".format(where, port, path) + url = f"https://[{where}]:{port}{path}" else: url = where - if http_version == HTTPVersion.H3 or (http_version == HTTPVersion.DEFAULT and not have_doh): + if http_version == HTTPVersion.H3 or ( + http_version == HTTPVersion.DEFAULT and not have_doh + ): if bootstrap_address is None: parsed = urllib.parse.urlparse(url) resolver = _maybe_get_resolver(resolver) @@ -533,8 +535,8 @@ def https( # status codes if response.status_code < 200 or response.status_code > 299: raise ValueError( - "{} responded with status code {}" - "\nResponse body: {}".format(where, response.status_code, response.content) + f"{where} responded with status code {response.status_code}" + f"\nResponse body: {response.content}" ) r = dns.message.from_wire( response.content, diff --git a/dns/rdata.py b/dns/rdata.py index 1b4a6a76..5f9d4713 100644 --- a/dns/rdata.py +++ b/dns/rdata.py @@ -434,15 +434,11 @@ class Rdata: continue if key not in parameters: raise AttributeError( - "'{}' object has no attribute '{}'".format( - self.__class__.__name__, key - ) + f"'{self.__class__.__name__}' object has no attribute '{key}'" ) if key in ("rdclass", "rdtype"): raise AttributeError( - "Cannot overwrite '{}' attribute '{}'".format( - self.__class__.__name__, key - ) + f"Cannot overwrite '{self.__class__.__name__}' attribute '{key}'" ) # Construct the parameter list. For each field, use the value in diff --git a/dns/rdataset.py b/dns/rdataset.py index 8bff58d7..b5bd40a3 100644 --- a/dns/rdataset.py +++ b/dns/rdataset.py @@ -248,12 +248,7 @@ class Rdataset(dns.set.Set): # (which is meaningless anyway). # s.write( - "{}{}{} {}\n".format( - ntext, - pad, - dns.rdataclass.to_text(rdclass), - dns.rdatatype.to_text(self.rdtype), - ) + f"{ntext}{pad}{dns.rdataclass.to_text(rdclass)} {dns.rdatatype.to_text(self.rdtype)}\n" ) else: for rd in self: diff --git a/dns/rdtypes/ANY/GPOS.py b/dns/rdtypes/ANY/GPOS.py index 312338f9..0aa33798 100644 --- a/dns/rdtypes/ANY/GPOS.py +++ b/dns/rdtypes/ANY/GPOS.py @@ -75,9 +75,7 @@ class GPOS(dns.rdata.Rdata): raise dns.exception.FormError("bad longitude") def to_text(self, origin=None, relativize=True, **kw): - return "{} {} {}".format( - self.latitude.decode(), self.longitude.decode(), self.altitude.decode() - ) + return f"{self.latitude.decode()} {self.longitude.decode()} {self.altitude.decode()}" @classmethod def from_text( diff --git a/dns/rdtypes/ANY/HINFO.py b/dns/rdtypes/ANY/HINFO.py index c2c45de0..06ad3487 100644 --- a/dns/rdtypes/ANY/HINFO.py +++ b/dns/rdtypes/ANY/HINFO.py @@ -37,9 +37,7 @@ class HINFO(dns.rdata.Rdata): self.os = self._as_bytes(os, True, 255) def to_text(self, origin=None, relativize=True, **kw): - return '"{}" "{}"'.format( - dns.rdata._escapify(self.cpu), dns.rdata._escapify(self.os) - ) + return f'"{dns.rdata._escapify(self.cpu)}" "{dns.rdata._escapify(self.os)}"' @classmethod def from_text( diff --git a/dns/rdtypes/ANY/ISDN.py b/dns/rdtypes/ANY/ISDN.py index fb01eab3..d2c44ed6 100644 --- a/dns/rdtypes/ANY/ISDN.py +++ b/dns/rdtypes/ANY/ISDN.py @@ -38,9 +38,7 @@ class ISDN(dns.rdata.Rdata): def to_text(self, origin=None, relativize=True, **kw): if self.subaddress: - return '"{}" "{}"'.format( - dns.rdata._escapify(self.address), dns.rdata._escapify(self.subaddress) - ) + return f'"{dns.rdata._escapify(self.address)}" "{dns.rdata._escapify(self.subaddress)}"' else: return '"%s"' % dns.rdata._escapify(self.address) diff --git a/dns/rdtypes/ANY/LOC.py b/dns/rdtypes/ANY/LOC.py index a36a2c10..ced5dc03 100644 --- a/dns/rdtypes/ANY/LOC.py +++ b/dns/rdtypes/ANY/LOC.py @@ -184,11 +184,7 @@ class LOC(dns.rdata.Rdata): or self.horizontal_precision != _default_hprec or self.vertical_precision != _default_vprec ): - 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, - ) + text += f" {self.size / 100.0:0.2f}m {self.horizontal_precision / 100.0:0.2f}m {self.vertical_precision / 100.0:0.2f}m" return text @classmethod diff --git a/dns/rdtypes/ANY/NSEC.py b/dns/rdtypes/ANY/NSEC.py index 340525a6..3c78b722 100644 --- a/dns/rdtypes/ANY/NSEC.py +++ b/dns/rdtypes/ANY/NSEC.py @@ -44,7 +44,7 @@ class NSEC(dns.rdata.Rdata): def to_text(self, origin=None, relativize=True, **kw): next = self.next.choose_relativity(origin, relativize) text = Bitmap(self.windows).to_text() - return "{}{}".format(next, text) + return f"{next}{text}" @classmethod def from_text( diff --git a/dns/rdtypes/ANY/RP.py b/dns/rdtypes/ANY/RP.py index 9b74549d..a66cfc50 100644 --- a/dns/rdtypes/ANY/RP.py +++ b/dns/rdtypes/ANY/RP.py @@ -37,7 +37,7 @@ class RP(dns.rdata.Rdata): def to_text(self, origin=None, relativize=True, **kw): mbox = self.mbox.choose_relativity(origin, relativize) txt = self.txt.choose_relativity(origin, relativize) - return "{} {}".format(str(mbox), str(txt)) + return f"{str(mbox)} {str(txt)}" @classmethod def from_text( diff --git a/dns/rdtypes/ANY/WALLET.py b/dns/rdtypes/ANY/WALLET.py index 4781ebc4..ff464763 100644 --- a/dns/rdtypes/ANY/WALLET.py +++ b/dns/rdtypes/ANY/WALLET.py @@ -3,6 +3,7 @@ import dns.immutable import dns.rdtypes.txtbase + @dns.immutable.immutable class WALLET(dns.rdtypes.txtbase.TXTBase): """WALLET record""" diff --git a/dns/rdtypes/txtbase.py b/dns/rdtypes/txtbase.py index 44d6df57..3e35b140 100644 --- a/dns/rdtypes/txtbase.py +++ b/dns/rdtypes/txtbase.py @@ -60,7 +60,7 @@ class TXTBase(dns.rdata.Rdata): txt = "" prefix = "" for s in self.strings: - txt += '{}"{}"'.format(prefix, dns.rdata._escapify(s)) + txt += f'{prefix}"{dns.rdata._escapify(s)}"' prefix = " " return txt diff --git a/dns/resolver.py b/dns/resolver.py index 1358c4c0..da63eaf8 100644 --- a/dns/resolver.py +++ b/dns/resolver.py @@ -83,7 +83,7 @@ class NXDOMAIN(dns.exception.DNSException): else: msg = "The DNS query name does not exist" qnames = ", ".join(map(str, qnames)) - return "{}: {}".format(msg, qnames) + return f"{msg}: {qnames}" @property def canonical_name(self): @@ -154,7 +154,7 @@ def _errors_to_text(errors: List[ErrorTuple]) -> List[str]: """Turn a resolution errors trace into a list of text.""" texts = [] for err in errors: - texts.append("Server {} answered {}".format(err[0], err[3])) + texts.append(f"Server {err[0]} answered {err[3]}") return texts @@ -1205,9 +1205,7 @@ class BaseResolver: enriched_nameservers.append(enriched_nameserver) else: raise ValueError( - "nameservers must be a list or tuple (not a {})".format( - type(nameservers) - ) + f"nameservers must be a list or tuple (not a {type(nameservers)})" ) return enriched_nameservers diff --git a/dns/zonefile.py b/dns/zonefile.py index 1836adf1..2bb44a52 100644 --- a/dns/zonefile.py +++ b/dns/zonefile.py @@ -251,9 +251,7 @@ class Reader: # We convert them to syntax errors so that we can emit # helpful filename:line info. (ty, va) = sys.exc_info()[:2] - raise dns.exception.SyntaxError( - "caught exception {}: {}".format(str(ty), str(va)) - ) + raise dns.exception.SyntaxError(f"caught exception {str(ty)}: {str(va)}") if not self.default_ttl_known and rdtype == dns.rdatatype.SOA: # The pre-RFC2308 and pre-BIND9 behavior inherits the zone default diff --git a/pyproject.toml b/pyproject.toml index 9c7ab988..71316241 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -113,7 +113,6 @@ lint.ignore = [ "B904", "B011", "UP031", - "UP032", ] lint.exclude = ["tests/*"] diff --git a/tests/test_async.py b/tests/test_async.py index f0c227de..b6e7a451 100644 --- a/tests/test_async.py +++ b/tests/test_async.py @@ -596,7 +596,7 @@ class AsyncTests(unittest.TestCase): @unittest.skipIf(not dns.quic.have_quic, "aioquic not available") def TestDoH3QueryIP(self): async def run(): - nameserver_ip = '8.8.8.8' + nameserver_ip = "8.8.8.8" q = dns.message.make_query("example.com.", dns.rdatatype.A) r = dns.asyncquery.https( q, diff --git a/tests/test_doh.py b/tests/test_doh.py index 900a3fae..f5d41308 100644 --- a/tests/test_doh.py +++ b/tests/test_doh.py @@ -248,5 +248,6 @@ class DNSOverHTTP3TestCase(unittest.TestCase): ) self.assertTrue(q.is_response(r)) + if __name__ == "__main__": unittest.main()