Compare commits

...

5 Commits

Author SHA1 Message Date
H. Shay
da5c58bb24 run pyupgrade --py37-plus --keep-percent-format on synapse/ 2022-01-04 12:50:21 -08:00
H. Shay
6e94f64edf lint 2022-01-04 11:02:04 -08:00
H. Shay
da1f496487 newsfragment 2022-01-04 10:50:46 -08:00
H. Shay
68882a0251 run pyupgrade on synapse/app and synapse/appservice 2022-01-04 10:24:57 -08:00
H. Shay
56d599e5ac run pyupgrade on synapse/_scripts and synapse/api 2022-01-04 10:23:16 -08:00
16 changed files with 26 additions and 28 deletions

1
changelog.d/11684.misc Normal file
View File

@@ -0,0 +1 @@
Run `pyupgrade --py36-plus` on `synapse/app`, `synapse/appservice`, `synapse/_scripts`, 'synapse/api'.

View File

@@ -38,7 +38,7 @@ def request_registration(
exit: Callable[[int], None] = sys.exit,
) -> None:
url = "%s/_synapse/admin/v1/register" % (server_location.rstrip("/"),)
url = "{}/_synapse/admin/v1/register".format(server_location.rstrip("/"))
# Get the nonce
r = requests.get(url, verify=False)
@@ -108,7 +108,7 @@ def register_new_user(
default_user = None
if default_user:
user = input("New user localpart [%s]: " % (default_user,))
user = input(f"New user localpart [{default_user}]: ")
if not user:
user = default_user
else:

View File

@@ -122,7 +122,7 @@ class Auth:
if not forgot:
return member
raise AuthError(403, "User %s not in room %s" % (user_id, room_id))
raise AuthError(403, f"User {user_id} not in room {room_id}")
async def get_user_by_req(
self,

View File

@@ -117,7 +117,7 @@ class RedirectException(CodeMessageException):
location: the URI to redirect to
http_code: the HTTP response code
"""
msg = "Redirect to %s" % (location.decode("utf-8"),)
msg = "Redirect to {}".format(location.decode("utf-8"))
super().__init__(code=http_code, msg=msg)
self.location = location
@@ -237,7 +237,7 @@ class FederationDeniedError(SynapseError):
super().__init__(
code=403,
msg="Federation denied with %s." % (self.destination,),
msg=f"Federation denied with {self.destination}.",
errcode=Codes.FORBIDDEN,
)
@@ -518,14 +518,14 @@ class FederationError(RuntimeError):
source: Optional[str] = None,
):
if level not in ["FATAL", "ERROR", "WARN"]:
raise ValueError("Level is not valid: %s" % (level,))
raise ValueError(f"Level is not valid: {level}")
self.level = level
self.code = code
self.reason = reason
self.affected = affected
self.source = source
msg = "%s %s: %s" % (level, code, reason)
msg = f"{level} {code}: {reason}"
super().__init__(msg)
def get_dict(self) -> "JsonDict":

View File

@@ -218,7 +218,7 @@ class FilterCollection:
self.event_format = filter_json.get("event_format", "client")
def __repr__(self) -> str:
return "<FilterCollection %s>" % (json.dumps(self._filter_json),)
return "<FilterCollection {}>".format(json.dumps(self._filter_json))
def get_filter_json(self) -> JsonDict:
return self._filter_json
@@ -418,7 +418,7 @@ class Filter:
for name, match_func in field_matchers.items():
# If the event matches one of the disallowed values, reject it.
not_name = "not_%s" % (name,)
not_name = f"not_{name}"
disallowed_values = getattr(self, not_name)
if any(map(match_func, disallowed_values)):
return False

View File

@@ -55,7 +55,7 @@ class ConsentURIBuilder:
mac = hmac.new(
key=self._hmac_secret, msg=user_id.encode("ascii"), digestmod=sha256
).hexdigest()
consent_uri = "%s_matrix/consent?%s" % (
consent_uri = "{}_matrix/consent?{}".format(
self._public_baseurl,
urlencode({"u": user_id, "h": mac}),
)

View File

@@ -183,7 +183,7 @@ def quit_with_error(error_string: str) -> NoReturn:
line_length = min(max(len(line) for line in message_lines), 80) + 2
sys.stderr.write("*" * line_length + "\n")
for line in message_lines:
sys.stderr.write(" %s\n" % (line.rstrip(),))
sys.stderr.write(f" {line.rstrip()}\n")
sys.stderr.write("*" * line_length + "\n")
sys.exit(1)

View File

@@ -102,7 +102,7 @@ class FileExfiltrationWriter(ExfiltrationWriter):
self.base_directory = directory
else:
self.base_directory = tempfile.mkdtemp(
prefix="synapse-exfiltrate__%s__" % (user_id,)
prefix=f"synapse-exfiltrate__{user_id}__"
)
os.makedirs(self.base_directory, exist_ok=True)

View File

@@ -381,7 +381,7 @@ class GenericWorkerServer(HomeServer):
bind_addresses,
port,
SynapseSite(
"synapse.access.http.%s" % (site_tag,),
f"synapse.access.http.{site_tag}",
site_tag,
listener_config,
root_resource,

View File

@@ -114,7 +114,7 @@ class SynapseHomeServer(HomeServer):
for path, resmodule in additional_resources.items():
handler_cls, config = load_module(
resmodule,
("listeners", site_tag, "additional_resources", "<%s>" % (path,)),
("listeners", site_tag, "additional_resources", f"<{path}>"),
)
handler = handler_cls(config, module_api)
if isinstance(handler, Resource):
@@ -141,7 +141,7 @@ class SynapseHomeServer(HomeServer):
root_resource = OptionsResource()
site = SynapseSite(
"synapse.access.%s.%s" % ("https" if tls else "http", site_tag),
"synapse.access.{}.{}".format("https" if tls else "http", site_tag),
site_tag,
listener_config,
create_resource_tree(resources, root_resource),
@@ -417,15 +417,15 @@ def format_config_error(e: ConfigError) -> Iterator[str]:
yield "Error in configuration"
if e.path:
yield " at '%s'" % (".".join(e.path),)
yield " at '{}'".format(".".join(e.path))
yield ":\n %s" % (e.msg,)
yield f":\n {e.msg}"
parent_e = e.__cause__
indent = 1
while parent_e:
indent += 1
yield ":\n%s%s" % (" " * indent, str(parent_e))
yield ":\n{}{}".format(" " * indent, str(parent_e))
parent_e = parent_e.__cause__

View File

@@ -143,7 +143,7 @@ async def phone_stats_home(
stats["log_level"] = logging.getLevelName(log_level)
logger.info(
"Reporting stats to %s: %s" % (hs.config.metrics.report_stats_endpoint, stats)
f"Reporting stats to {hs.config.metrics.report_stats_endpoint}: {stats}"
)
try:
await hs.get_proxied_http_client().put_json(

View File

@@ -339,7 +339,7 @@ class ApplicationService:
dict_copy = self.__dict__.copy()
dict_copy["token"] = "<redacted>"
dict_copy["hs_token"] = "<redacted>"
return "ApplicationService: %s" % (dict_copy,)
return f"ApplicationService: {dict_copy}"
class AppServiceTransaction:

View File

@@ -149,7 +149,7 @@ class ApplicationServiceApi(SimpleHttpClient):
if service.url is None:
return []
uri = "%s%s/thirdparty/%s/%s" % (
uri = "{}{}/thirdparty/{}/{}".format(
service.url,
APP_SERVICE_PREFIX,
kind,
@@ -184,7 +184,7 @@ class ApplicationServiceApi(SimpleHttpClient):
return {}
async def _get() -> Optional[JsonDict]:
uri = "%s%s/thirdparty/protocol/%s" % (
uri = "{}{}/thirdparty/protocol/{}".format(
service.url,
APP_SERVICE_PREFIX,
urllib.parse.quote(protocol),

View File

@@ -133,7 +133,7 @@ class _ServiceQueuer:
return
run_as_background_process(
"as-sender-%s" % (service.id,), self._send_request, service
f"as-sender-{service.id}", self._send_request, service
)
def enqueue_event(self, service: ApplicationService, event: EventBase) -> None:
@@ -281,9 +281,7 @@ class _Recoverer:
def recover(self) -> None:
def _retry() -> None:
run_as_background_process(
"as-recoverer-%s" % (self.service.id,), self.retry
)
run_as_background_process(f"as-recoverer-{self.service.id}", self.retry)
delay = 2 ** self.backoff_counter
logger.info("Scheduling retries on %s in %fs", self.service.id, delay)

View File

@@ -466,7 +466,7 @@ class UserMediaRestServlet(RestServlet):
)
deleted_media, total = await self.media_repository.delete_local_media_ids(
([row["media_id"] for row in media])
[row["media_id"] for row in media]
)
return HTTPStatus.OK, {"deleted_media": deleted_media, "total": total}

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2021 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");