From a77a254b31712ee02da6053e1ac04c147fa50b9c Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 13 Aug 2020 13:49:47 +0300 Subject: [PATCH] Run lint fix --- synapse/handlers/federation.py | 12 ++++-- synapse/rest/__init__.py | 2 +- synapse/rest/client/v2_alpha/forward_event.py | 43 +++++++++++++------ 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index 79b6ccf66..f52204b15 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -50,11 +50,11 @@ from synapse.api.errors import ( ) from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, RoomVersion, RoomVersions from synapse.crypto.event_signing import compute_event_signature -from synapse.federation.federation_base import FederationBase, event_from_pdu_json from synapse.event_auth import auth_types_for_event from synapse.events import EventBase from synapse.events.snapshot import EventContext from synapse.events.validator import EventValidator +from synapse.federation.federation_base import FederationBase, event_from_pdu_json from synapse.handlers._base import BaseHandler from synapse.logging.context import ( make_deferred_yieldable, @@ -680,7 +680,9 @@ class FederationHandler(BaseHandler, FederationBase): _forwarded_key = "net.maunium.msc2730.forwarded" - async def _validate_forwarded_event(self, event: EventBase) -> Tuple[bool, Optional[str]]: + async def _validate_forwarded_event( + self, event: EventBase + ) -> Tuple[bool, Optional[str]]: try: source_evt_dict = {**event.content[self._forwarded_key]} room_version_identifier = source_evt_dict["unsigned"]["room_version"] @@ -734,7 +736,11 @@ class FederationHandler(BaseHandler, FederationBase): logger.debug("[%s %s] Processing event: %s", room_id, event_id, event) - if not event.is_state() and not event.redacts and self._forwarded_key in event.content: + if ( + not event.is_state() + and not event.redacts + and self._forwarded_key in event.content + ): valid, event_id = await self._validate_forwarded_event(event) event.unsigned[self._forwarded_key] = { "valid": valid, diff --git a/synapse/rest/__init__.py b/synapse/rest/__init__.py index 811982578..684e94a82 100644 --- a/synapse/rest/__init__.py +++ b/synapse/rest/__init__.py @@ -37,6 +37,7 @@ from synapse.rest.client.v2_alpha import ( capabilities, devices, filter, + forward_event, groups, keys, notifications, @@ -47,7 +48,6 @@ from synapse.rest.client.v2_alpha import ( register, relations, report_event, - forward_event, room_keys, room_upgrade_rest_servlet, sendtodevice, diff --git a/synapse/rest/client/v2_alpha/forward_event.py b/synapse/rest/client/v2_alpha/forward_event.py index 8fbae6597..863d1baa6 100644 --- a/synapse/rest/client/v2_alpha/forward_event.py +++ b/synapse/rest/client/v2_alpha/forward_event.py @@ -16,7 +16,7 @@ import logging -from synapse.api.errors import Codes, SynapseError, AuthError +from synapse.api.errors import AuthError, Codes, SynapseError from synapse.http.servlet import RestServlet, parse_integer from synapse.logging.opentracing import set_tag @@ -31,8 +31,10 @@ class RoomEventForwardServlet(RestServlet): """ PATTERNS = client_patterns( - ("/net.maunium.msc2730/rooms/(?P[^/]*)/event/(?P[^/]*)" - "/forward/(?P[^/]*)/(?P.*)"), + ( + "/net.maunium.msc2730/rooms/(?P[^/]*)/event/(?P[^/]*)" + "/forward/(?P[^/]*)/(?P.*)" + ), releases=(), # This is an unstable feature ) @@ -59,14 +61,23 @@ class RoomEventForwardServlet(RestServlet): raise SynapseError(404, "Event not found.", errcode=Codes.NOT_FOUND) if event.is_state(): - raise SynapseError(401, "State events cannot be forwarded.", - errcode=self._err_not_forwardable) + raise SynapseError( + 401, + "State events cannot be forwarded.", + errcode=self._err_not_forwardable, + ) elif event.redacts: - raise SynapseError(401, "Redaction events cannot be forwarded.", - errcode=self._err_not_forwardable) + raise SynapseError( + 401, + "Redaction events cannot be forwarded.", + errcode=self._err_not_forwardable, + ) elif event.internal_metadata.is_redacted(): - raise SynapseError(401, "Redacted events cannot be forwarded.", - errcode=self._err_not_forwardable) + raise SynapseError( + 401, + "Redacted events cannot be forwarded.", + errcode=self._err_not_forwardable, + ) event_id = event.event_id event_dict = event.get_dict() @@ -81,8 +92,11 @@ class RoomEventForwardServlet(RestServlet): is_valid_forward = False if has_forward_meta and not is_valid_forward: - raise SynapseError(401, "Event contains invalid forward metadata.", - errcode=self._err_not_forwardable) + raise SynapseError( + 401, + "Event contains invalid forward metadata.", + errcode=self._err_not_forwardable, + ) elif not has_forward_meta: content[self._data_key] = event_dict room_version = await self.store.get_room_version(event.room_id) @@ -101,13 +115,16 @@ class RoomEventForwardServlet(RestServlet): "valid": True, "event_id": event_id, } - } + }, } if b"ts" in request.args and requester.app_service: forwarded_event_dict["origin_server_ts"] = parse_integer(request, "ts", 0) - forwarded_event, _ = await self.event_creation_handler.create_and_send_nonmember_event( + ( + forwarded_event, + _, + ) = await self.event_creation_handler.create_and_send_nonmember_event( requester, forwarded_event_dict, txn_id=txn_id )