replace old %-formatted and .format(…) strings with f-strings (#7671)

mostly using flynt
https://github.com/ikamensh/flynt
This commit is contained in:
Mike Fährmann
2025-06-28 19:36:16 +02:00
parent f77e98b57d
commit 9dbe33b6de
167 changed files with 756 additions and 891 deletions

View File

@@ -89,12 +89,12 @@ class OAuthBase(Extractor):
else:
self.log.info("Please open this URL in your browser:")
stdout_write("\n{}\n\n".format(url))
stdout_write(f"\n{url}\n\n")
return (recv or self.recv)()
def error(self, msg):
return self.send(
"Remote server reported an error:\n\n{}\n".format(msg))
f"Remote server reported an error:\n\n{msg}\n")
def _oauth1_authorization_flow(
self, default_key, default_secret,
@@ -151,10 +151,7 @@ class OAuthBase(Extractor):
"default" if client_id == default_id else "custom",
instance or self.subcategory, client_id)
state = "gallery-dl_{}_{}".format(
self.subcategory,
oauth.nonce(8),
)
state = f"gallery-dl_{self.subcategory}_{oauth.nonce(8)}"
auth_params = {
"client_id" : client_id,
@@ -170,8 +167,8 @@ class OAuthBase(Extractor):
# check authorization response
if state != params.get("state"):
self.send("'state' mismatch: expected {}, got {}.\n".format(
state, params.get("state")))
self.send(f"'state' mismatch: expected {state}, "
f"got {params.get('state')}.\n")
return
if "error" in params:
return self.error(params)
@@ -233,11 +230,9 @@ class OAuthBase(Extractor):
for n in names
)
if self.cache:
msg += (
"\nor set\n'extractor.{}.{}' to \"cache\""
.format(self.subcategory, names[0])
)
msg += "\nto use {}.\n".format(_it)
msg = (f"{msg}\nor set\n'extractor."
f"{self.subcategory}.{names[0]}' to \"cache\"")
msg = f"{msg}\nto use {_it}.\n"
return msg
@@ -371,8 +366,8 @@ class OAuthMastodon(OAuthBase):
application["client-secret"],
application["client-id"],
application["client-secret"],
"https://{}/oauth/authorize".format(self.instance),
"https://{}/oauth/token".format(self.instance),
f"https://{self.instance}/oauth/authorize",
f"https://{self.instance}/oauth/token",
instance=self.instance,
key="access_token",
cache=mastodon._access_token_cache,
@@ -382,7 +377,7 @@ class OAuthMastodon(OAuthBase):
def _register(self, instance):
self.log.info("Registering application for '%s'", instance)
url = "https://{}/api/v1/apps".format(instance)
url = f"https://{instance}/api/v1/apps"
data = {
"client_name": "gdl:" + oauth.nonce(8),
"redirect_uris": self.redirect_uri,
@@ -447,7 +442,7 @@ class OAuthPixiv(OAuthBase):
url, method="POST", headers=headers, data=data).json()
if "error" in data:
stdout_write("\n{}\n".format(data))
stdout_write(f"\n{data}\n")
if data["error"] in ("invalid_request", "invalid_grant"):
stdout_write("'code' expired, try again\n\n")
return