mirror of
https://github.com/element-hq/synapse.git
synced 2025-12-19 02:20:44 +00:00
Compare commits
5 Commits
travis/pre
...
shay/pyupg
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da5c58bb24 | ||
|
|
6e94f64edf | ||
|
|
da1f496487 | ||
|
|
68882a0251 | ||
|
|
56d599e5ac |
1
changelog.d/11684.misc
Normal file
1
changelog.d/11684.misc
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Run `pyupgrade --py36-plus` on `synapse/app`, `synapse/appservice`, `synapse/_scripts`, 'synapse/api'.
|
||||||
@@ -38,7 +38,7 @@ def request_registration(
|
|||||||
exit: Callable[[int], None] = sys.exit,
|
exit: Callable[[int], None] = sys.exit,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
url = "%s/_synapse/admin/v1/register" % (server_location.rstrip("/"),)
|
url = "{}/_synapse/admin/v1/register".format(server_location.rstrip("/"))
|
||||||
|
|
||||||
# Get the nonce
|
# Get the nonce
|
||||||
r = requests.get(url, verify=False)
|
r = requests.get(url, verify=False)
|
||||||
@@ -108,7 +108,7 @@ def register_new_user(
|
|||||||
default_user = None
|
default_user = None
|
||||||
|
|
||||||
if default_user:
|
if default_user:
|
||||||
user = input("New user localpart [%s]: " % (default_user,))
|
user = input(f"New user localpart [{default_user}]: ")
|
||||||
if not user:
|
if not user:
|
||||||
user = default_user
|
user = default_user
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ class Auth:
|
|||||||
if not forgot:
|
if not forgot:
|
||||||
return member
|
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(
|
async def get_user_by_req(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ class RedirectException(CodeMessageException):
|
|||||||
location: the URI to redirect to
|
location: the URI to redirect to
|
||||||
http_code: the HTTP response code
|
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)
|
super().__init__(code=http_code, msg=msg)
|
||||||
self.location = location
|
self.location = location
|
||||||
|
|
||||||
@@ -237,7 +237,7 @@ class FederationDeniedError(SynapseError):
|
|||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
code=403,
|
code=403,
|
||||||
msg="Federation denied with %s." % (self.destination,),
|
msg=f"Federation denied with {self.destination}.",
|
||||||
errcode=Codes.FORBIDDEN,
|
errcode=Codes.FORBIDDEN,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -518,14 +518,14 @@ class FederationError(RuntimeError):
|
|||||||
source: Optional[str] = None,
|
source: Optional[str] = None,
|
||||||
):
|
):
|
||||||
if level not in ["FATAL", "ERROR", "WARN"]:
|
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.level = level
|
||||||
self.code = code
|
self.code = code
|
||||||
self.reason = reason
|
self.reason = reason
|
||||||
self.affected = affected
|
self.affected = affected
|
||||||
self.source = source
|
self.source = source
|
||||||
|
|
||||||
msg = "%s %s: %s" % (level, code, reason)
|
msg = f"{level} {code}: {reason}"
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
|
|
||||||
def get_dict(self) -> "JsonDict":
|
def get_dict(self) -> "JsonDict":
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ class FilterCollection:
|
|||||||
self.event_format = filter_json.get("event_format", "client")
|
self.event_format = filter_json.get("event_format", "client")
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
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:
|
def get_filter_json(self) -> JsonDict:
|
||||||
return self._filter_json
|
return self._filter_json
|
||||||
@@ -418,7 +418,7 @@ class Filter:
|
|||||||
|
|
||||||
for name, match_func in field_matchers.items():
|
for name, match_func in field_matchers.items():
|
||||||
# If the event matches one of the disallowed values, reject it.
|
# 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)
|
disallowed_values = getattr(self, not_name)
|
||||||
if any(map(match_func, disallowed_values)):
|
if any(map(match_func, disallowed_values)):
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class ConsentURIBuilder:
|
|||||||
mac = hmac.new(
|
mac = hmac.new(
|
||||||
key=self._hmac_secret, msg=user_id.encode("ascii"), digestmod=sha256
|
key=self._hmac_secret, msg=user_id.encode("ascii"), digestmod=sha256
|
||||||
).hexdigest()
|
).hexdigest()
|
||||||
consent_uri = "%s_matrix/consent?%s" % (
|
consent_uri = "{}_matrix/consent?{}".format(
|
||||||
self._public_baseurl,
|
self._public_baseurl,
|
||||||
urlencode({"u": user_id, "h": mac}),
|
urlencode({"u": user_id, "h": mac}),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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
|
line_length = min(max(len(line) for line in message_lines), 80) + 2
|
||||||
sys.stderr.write("*" * line_length + "\n")
|
sys.stderr.write("*" * line_length + "\n")
|
||||||
for line in message_lines:
|
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.stderr.write("*" * line_length + "\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ class FileExfiltrationWriter(ExfiltrationWriter):
|
|||||||
self.base_directory = directory
|
self.base_directory = directory
|
||||||
else:
|
else:
|
||||||
self.base_directory = tempfile.mkdtemp(
|
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)
|
os.makedirs(self.base_directory, exist_ok=True)
|
||||||
|
|||||||
@@ -381,7 +381,7 @@ class GenericWorkerServer(HomeServer):
|
|||||||
bind_addresses,
|
bind_addresses,
|
||||||
port,
|
port,
|
||||||
SynapseSite(
|
SynapseSite(
|
||||||
"synapse.access.http.%s" % (site_tag,),
|
f"synapse.access.http.{site_tag}",
|
||||||
site_tag,
|
site_tag,
|
||||||
listener_config,
|
listener_config,
|
||||||
root_resource,
|
root_resource,
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ class SynapseHomeServer(HomeServer):
|
|||||||
for path, resmodule in additional_resources.items():
|
for path, resmodule in additional_resources.items():
|
||||||
handler_cls, config = load_module(
|
handler_cls, config = load_module(
|
||||||
resmodule,
|
resmodule,
|
||||||
("listeners", site_tag, "additional_resources", "<%s>" % (path,)),
|
("listeners", site_tag, "additional_resources", f"<{path}>"),
|
||||||
)
|
)
|
||||||
handler = handler_cls(config, module_api)
|
handler = handler_cls(config, module_api)
|
||||||
if isinstance(handler, Resource):
|
if isinstance(handler, Resource):
|
||||||
@@ -141,7 +141,7 @@ class SynapseHomeServer(HomeServer):
|
|||||||
root_resource = OptionsResource()
|
root_resource = OptionsResource()
|
||||||
|
|
||||||
site = SynapseSite(
|
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,
|
site_tag,
|
||||||
listener_config,
|
listener_config,
|
||||||
create_resource_tree(resources, root_resource),
|
create_resource_tree(resources, root_resource),
|
||||||
@@ -417,15 +417,15 @@ def format_config_error(e: ConfigError) -> Iterator[str]:
|
|||||||
yield "Error in configuration"
|
yield "Error in configuration"
|
||||||
|
|
||||||
if e.path:
|
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__
|
parent_e = e.__cause__
|
||||||
indent = 1
|
indent = 1
|
||||||
while parent_e:
|
while parent_e:
|
||||||
indent += 1
|
indent += 1
|
||||||
yield ":\n%s%s" % (" " * indent, str(parent_e))
|
yield ":\n{}{}".format(" " * indent, str(parent_e))
|
||||||
parent_e = parent_e.__cause__
|
parent_e = parent_e.__cause__
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ async def phone_stats_home(
|
|||||||
stats["log_level"] = logging.getLevelName(log_level)
|
stats["log_level"] = logging.getLevelName(log_level)
|
||||||
|
|
||||||
logger.info(
|
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:
|
try:
|
||||||
await hs.get_proxied_http_client().put_json(
|
await hs.get_proxied_http_client().put_json(
|
||||||
|
|||||||
@@ -339,7 +339,7 @@ class ApplicationService:
|
|||||||
dict_copy = self.__dict__.copy()
|
dict_copy = self.__dict__.copy()
|
||||||
dict_copy["token"] = "<redacted>"
|
dict_copy["token"] = "<redacted>"
|
||||||
dict_copy["hs_token"] = "<redacted>"
|
dict_copy["hs_token"] = "<redacted>"
|
||||||
return "ApplicationService: %s" % (dict_copy,)
|
return f"ApplicationService: {dict_copy}"
|
||||||
|
|
||||||
|
|
||||||
class AppServiceTransaction:
|
class AppServiceTransaction:
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ class ApplicationServiceApi(SimpleHttpClient):
|
|||||||
if service.url is None:
|
if service.url is None:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
uri = "%s%s/thirdparty/%s/%s" % (
|
uri = "{}{}/thirdparty/{}/{}".format(
|
||||||
service.url,
|
service.url,
|
||||||
APP_SERVICE_PREFIX,
|
APP_SERVICE_PREFIX,
|
||||||
kind,
|
kind,
|
||||||
@@ -184,7 +184,7 @@ class ApplicationServiceApi(SimpleHttpClient):
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
async def _get() -> Optional[JsonDict]:
|
async def _get() -> Optional[JsonDict]:
|
||||||
uri = "%s%s/thirdparty/protocol/%s" % (
|
uri = "{}{}/thirdparty/protocol/{}".format(
|
||||||
service.url,
|
service.url,
|
||||||
APP_SERVICE_PREFIX,
|
APP_SERVICE_PREFIX,
|
||||||
urllib.parse.quote(protocol),
|
urllib.parse.quote(protocol),
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ class _ServiceQueuer:
|
|||||||
return
|
return
|
||||||
|
|
||||||
run_as_background_process(
|
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:
|
def enqueue_event(self, service: ApplicationService, event: EventBase) -> None:
|
||||||
@@ -281,9 +281,7 @@ class _Recoverer:
|
|||||||
|
|
||||||
def recover(self) -> None:
|
def recover(self) -> None:
|
||||||
def _retry() -> None:
|
def _retry() -> None:
|
||||||
run_as_background_process(
|
run_as_background_process(f"as-recoverer-{self.service.id}", self.retry)
|
||||||
"as-recoverer-%s" % (self.service.id,), self.retry
|
|
||||||
)
|
|
||||||
|
|
||||||
delay = 2 ** self.backoff_counter
|
delay = 2 ** self.backoff_counter
|
||||||
logger.info("Scheduling retries on %s in %fs", self.service.id, delay)
|
logger.info("Scheduling retries on %s in %fs", self.service.id, delay)
|
||||||
|
|||||||
@@ -466,7 +466,7 @@ class UserMediaRestServlet(RestServlet):
|
|||||||
)
|
)
|
||||||
|
|
||||||
deleted_media, total = await self.media_repository.delete_local_media_ids(
|
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}
|
return HTTPStatus.OK, {"deleted_media": deleted_media, "total": total}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright 2021 The Matrix.org Foundation C.I.C.
|
# Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|||||||
Reference in New Issue
Block a user