Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

[pyupgrade] app/, appservice/, api/, _scripts/, and ./*.py #9751

Closed
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
1 change: 0 additions & 1 deletion synapse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
# Copyright 2018-9 New Vector Ltd
#
Expand Down
5 changes: 2 additions & 3 deletions synapse/_scripts/register_new_matrix_user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015, 2016 OpenMarket Ltd
# Copyright 2018 New Vector
#
Expand Down Expand Up @@ -37,7 +36,7 @@ def request_registration(
exit=sys.exit,
):

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)
Expand Down Expand Up @@ -100,7 +99,7 @@ def register_new_user(user, password, server_location, shared_secret, admin, use
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:
Expand Down
1 change: 0 additions & 1 deletion synapse/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 1 addition & 2 deletions synapse/api/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014 - 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -147,7 +146,7 @@ async def check_user_in_room(
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 check_host_in_room(self, room_id, host):
with Measure(self.clock, "check_host_in_room"):
Expand Down
1 change: 0 additions & 1 deletion synapse/api/auth_blocking.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2020 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/api/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
# Copyright 2017 Vector Creations Ltd
# Copyright 2018-2019 New Vector Ltd
Expand Down
9 changes: 4 additions & 5 deletions synapse/api/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
# Copyright 2018 New Vector Ltd
#
Expand Down Expand Up @@ -115,7 +114,7 @@ def __init__(self, location: bytes, http_code: int = http.FOUND):
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

Expand Down Expand Up @@ -227,7 +226,7 @@ def __init__(self, destination: Optional[str]):

super().__init__(
code=403,
msg="Federation denied with %s." % (self.destination,),
msg=f"Federation denied with {self.destination}.",
errcode=Codes.FORBIDDEN,
)

Expand Down Expand Up @@ -531,14 +530,14 @@ def __init__(
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):
Expand Down
5 changes: 2 additions & 3 deletions synapse/api/filtering.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015, 2016 OpenMarket Ltd
# Copyright 2017 Vector Creations Ltd
# Copyright 2018-2019 New Vector Ltd
Expand Down Expand Up @@ -190,7 +189,7 @@ def __init__(self, filter_json):
self.event_format = filter_json.get("event_format", "client")

def __repr__(self):
return "<FilterCollection %s>" % (json.dumps(self._filter_json),)
return "<FilterCollection {}>".format(json.dumps(self._filter_json))

def get_filter_json(self):
return self._filter_json
Expand Down Expand Up @@ -327,7 +326,7 @@ def check_fields(self, room_id, sender, event_type, labels, contains_url):
}

for name, match_func in literal_keys.items():
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
Expand Down
1 change: 0 additions & 1 deletion synapse/api/presence.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/api/room_versions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2019 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 1 addition & 2 deletions synapse/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
# Copyright 2018 New Vector Ltd
#
Expand Down Expand Up @@ -61,7 +60,7 @@ def build_user_consent_uri(self, user_id):
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}),
)
Expand Down
1 change: 0 additions & 1 deletion synapse/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 1 addition & 2 deletions synapse/app/_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 New Vector Ltd
# Copyright 2019-2021 The Matrix.org Foundation C.I.C
#
Expand Down Expand Up @@ -142,7 +141,7 @@ def quit_with_error(error_string: str) -> NoReturn:
line_length = max(len(line) for line in message_lines if len(line) < 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)

Expand Down
3 changes: 1 addition & 2 deletions synapse/app/admin_cmd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2019 Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -114,7 +113,7 @@ def __init__(self, user_id, directory=None):
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)
Expand Down
1 change: 0 additions & 1 deletion synapse/app/appservice.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/app/client_reader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/app/event_creator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2018 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/app/federation_reader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/app/federation_sender.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/app/frontend_proxy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
13 changes: 5 additions & 8 deletions synapse/app/generic_worker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2016 OpenMarket Ltd
# Copyright 2020 The Matrix.org Foundation C.I.C.
#
Expand Down Expand Up @@ -623,7 +622,7 @@ def _listen_http(self, listener_config: ListenerConfig):
bind_addresses,
port,
SynapseSite(
"synapse.access.http.%s" % (site_tag,),
f"synapse.access.http.{site_tag}",
site_tag,
listener_config,
root_resource,
Expand All @@ -645,10 +644,8 @@ def start_listening(self, listeners: Iterable[ListenerConfig]):
elif listener.type == "metrics":
if not self.get_config().enable_metrics:
logger.warning(
(
"Metrics listener configured, but "
"enable_metrics is not True!"
)
"Metrics listener configured, but "
"enable_metrics is not True!"
)
else:
_base.listen_metrics(listener.bind_addresses, listener.port)
Expand Down Expand Up @@ -742,7 +739,7 @@ def stop_pusher(self, user_id, app_id, pushkey):
if not self.notify_pushers:
return

key = "%s:%s" % (app_id, pushkey)
key = f"{app_id}:{pushkey}"
pushers_for_user = self.pusher_pool.pushers.get(user_id, {})
pusher = pushers_for_user.pop(key, None)
if pusher is None:
Expand All @@ -754,7 +751,7 @@ async def start_pusher(self, user_id, app_id, pushkey):
if not self.notify_pushers:
return

key = "%s:%s" % (app_id, pushkey)
key = f"{app_id}:{pushkey}"
logger.info("Starting pusher %r / %r", user_id, key)
return await self.pusher_pool.start_pusher_by_id(app_id, pushkey, user_id)

Expand Down
21 changes: 9 additions & 12 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
# Copyright 2019 New Vector Ltd
#
Expand Down Expand Up @@ -105,7 +104,7 @@ def _listener_http(self, config: HomeServerConfig, listener_config: ListenerConf
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 IResource.providedBy(handler):
Expand Down Expand Up @@ -134,7 +133,7 @@ def _listener_http(self, config: HomeServerConfig, listener_config: ListenerConf
bind_addresses,
port,
SynapseSite(
"synapse.access.https.%s" % (site_tag,),
f"synapse.access.https.{site_tag}",
site_tag,
listener_config,
root_resource,
Expand All @@ -150,7 +149,7 @@ def _listener_http(self, config: HomeServerConfig, listener_config: ListenerConf
bind_addresses,
port,
SynapseSite(
"synapse.access.http.%s" % (site_tag,),
f"synapse.access.http.{site_tag}",
site_tag,
listener_config,
root_resource,
Expand Down Expand Up @@ -301,10 +300,8 @@ def start_listening(self, listeners: Iterable[ListenerConfig]):
elif listener.type == "metrics":
if not self.get_config().enable_metrics:
logger.warning(
(
"Metrics listener configured, but "
"enable_metrics is not True!"
)
"Metrics listener configured, but "
"enable_metrics is not True!"
)
else:
_base.listen_metrics(listener.bind_addresses, listener.port)
Expand Down Expand Up @@ -356,7 +353,7 @@ def setup(config_options):
except IncorrectDatabaseSetup as e:
quit_with_error(str(e))
except UpgradeDatabaseException as e:
quit_with_error("Failed to upgrade database: %s" % (e,))
quit_with_error(f"Failed to upgrade database: {e}")

async def do_acme() -> bool:
"""
Expand Down Expand Up @@ -442,15 +439,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}"

e = e.__cause__
indent = 1
while e:
indent += 1
yield ":\n%s%s" % (" " * indent, str(e))
yield ":\n{}{}".format(" " * indent, str(e))
e = e.__cause__


Expand Down
1 change: 0 additions & 1 deletion synapse/app/media_repository.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion synapse/app/phone_stats_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async def phone_stats_home(hs, stats, stats_process=_stats_process):
log_level = synapse_logger.getEffectiveLevel()
stats["log_level"] = logging.getLevelName(log_level)

logger.info("Reporting stats to %s: %s" % (hs.config.report_stats_endpoint, stats))
logger.info(f"Reporting stats to {hs.config.report_stats_endpoint}: {stats}")
try:
await hs.get_proxied_http_client().put_json(
hs.config.report_stats_endpoint, stats
Expand Down
1 change: 0 additions & 1 deletion synapse/app/pusher.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/app/synchrotron.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/app/user_dir.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2017 Vector Creations Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 1 addition & 2 deletions synapse/appservice/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015, 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -318,7 +317,7 @@ def __str__(self):
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:
Expand Down
Loading