From 9b5e057af135bf1c5d16a687a100d3ab62a5abff Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 4 Feb 2021 22:37:31 -0600 Subject: [PATCH] Fix some lint --- synapse/events/builder.py | 5 ++++- synapse/handlers/message.py | 4 +++- synapse/handlers/sync.py | 5 +---- synapse/http/servlet.py | 21 ++++++++++----------- synapse/rest/client/v1/room.py | 4 +++- synapse/visibility.py | 6 +++--- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/synapse/events/builder.py b/synapse/events/builder.py index e9bc1524559b..ea98e6312c6a 100644 --- a/synapse/events/builder.py +++ b/synapse/events/builder.py @@ -98,7 +98,10 @@ def is_state(self): return self._state_key is not None async def build( - self, prev_event_ids: List[str], overriding_prev_events: False, auth_event_ids: Optional[List[str]], + self, + prev_event_ids: List[str], + overriding_prev_events: False, + auth_event_ids: Optional[List[str]], ) -> EventBase: """Transform into a fully signed and hashed event diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 5e19e630cacd..a53f71f64969 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -815,7 +815,9 @@ async def create_new_client_event( ), "Attempting to create an event with no prev_events" event = await builder.build( - prev_event_ids=prev_event_ids, overriding_prev_events=overriding_prev_events, auth_event_ids=auth_event_ids + prev_event_ids=prev_event_ids, + overriding_prev_events=overriding_prev_events, + auth_event_ids=auth_event_ids, ) context = await self.state.compute_event_context(event) if requester: diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py index 6d7c00285c0c..afbea5e58af2 100644 --- a/synapse/handlers/sync.py +++ b/synapse/handlers/sync.py @@ -42,10 +42,7 @@ from synapse.util.caches.lrucache import LruCache from synapse.util.caches.response_cache import ResponseCache from synapse.util.metrics import Measure, measure_func -from synapse.visibility import ( - filter_events_for_client, - filter_historical_events -) +from synapse.visibility import filter_events_for_client, filter_historical_events if TYPE_CHECKING: from synapse.server import HomeServer diff --git a/synapse/http/servlet.py b/synapse/http/servlet.py index fd1c98ad317d..ed8ea7be3ed2 100644 --- a/synapse/http/servlet.py +++ b/synapse/http/servlet.py @@ -148,19 +148,12 @@ def parse_string( ) -def parse_string_value( - value, - allowed_values, - name="", - encoding="ascii" -) -> str: +def parse_string_value(value, allowed_values, name="", encoding="ascii") -> str: if encoding: try: value = value.decode(encoding) except ValueError: - raise SynapseError( - 400, "Query parameter %r must be %s" % (name, encoding) - ) + raise SynapseError(400, "Query parameter %r must be %s" % (name, encoding)) if allowed_values is not None and value not in allowed_values: message = "Query parameter %r must be one of [%s]" % ( @@ -171,6 +164,7 @@ def parse_string_value( else: return value + def parse_strings_from_args( args, name, @@ -187,7 +181,10 @@ def parse_strings_from_args( if name in args: values = args[name] - return [parse_string_value(value, allowed_values, name=name, encoding=encoding) for value in values] + return [ + parse_string_value(value, allowed_values, name=name, encoding=encoding) + for value in values + ] else: if required: message = "Missing %s query parameter %r" % (param_type, name) @@ -218,13 +215,14 @@ def parse_string_from_args( param_type=param_type, encoding=encoding, ) - + if isinstance(strings, list) and len(strings): return strings[0] # Return the default return strings + def parse_json_value_from_request(request, allow_empty_body=False): """Parse a JSON value from the body of a twisted HTTP request. @@ -279,6 +277,7 @@ def parse_json_object_from_request(request, allow_empty_body=False): return content + def assert_params_in_dict(body, required): absent = [] for k in required: diff --git a/synapse/rest/client/v1/room.py b/synapse/rest/client/v1/room.py index 2770a73b26a5..884e59bf01db 100644 --- a/synapse/rest/client/v1/room.py +++ b/synapse/rest/client/v1/room.py @@ -230,12 +230,14 @@ async def on_POST(self, request, room_id, event_type, txn_id=None): "type": event_type, "content": content, "room_id": room_id, - "sender": requester.user.to_string() + "sender": requester.user.to_string(), } if prev_events: event_dict["prev_events"] = prev_events + # TODO: Put app_service logic back in place once we figure out how to make the Complement tests + # run as an app service if b"ts" in request.args: # and requester.app_service: event_dict["origin_server_ts"] = parse_integer(request, "ts", 0) diff --git a/synapse/visibility.py b/synapse/visibility.py index 3b49676e3e11..cee6739b1b75 100644 --- a/synapse/visibility.py +++ b/synapse/visibility.py @@ -45,9 +45,8 @@ Membership.BAN, ) -async def filter_historical_events( - events -): + +async def filter_historical_events(events): filtered_events = [e for e in events if not e.content.get("m.historical", None)] # remove the None entries @@ -56,6 +55,7 @@ async def filter_historical_events( # we turn it into a list before returning it. return list(filtered_events) + async def filter_events_for_client( storage: Storage, user_id,