From 3fb2ea99329ad2c4f054deff83ad19af571241f8 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Thu, 14 May 2020 11:51:16 +0100 Subject: [PATCH] apply linting --- synapse/config/_base.py | 2 +- synapse/config/registration.py | 6 ++--- synapse/events/spamcheck.py | 2 +- synapse/handlers/account_validity.py | 4 +++- synapse/handlers/federation.py | 3 +-- synapse/handlers/identity.py | 24 +++++++++---------- synapse/handlers/register.py | 12 +++++----- synapse/handlers/room_member.py | 10 +------- synapse/rest/client/v2_alpha/account.py | 11 +++++---- synapse/rest/client/v2_alpha/account_data.py | 2 -- synapse/rest/client/versions.py | 8 +++---- synapse/storage/data_stores/main/profile.py | 2 -- .../test_matrix_federation_agent.py | 4 +--- tests/rest/client/test_identity.py | 8 +++---- tests/rest/client/test_room_access_rules.py | 9 +++---- 15 files changed, 48 insertions(+), 59 deletions(-) diff --git a/synapse/config/_base.py b/synapse/config/_base.py index eda2b65ef7..132e48447c 100644 --- a/synapse/config/_base.py +++ b/synapse/config/_base.py @@ -18,8 +18,8 @@ import argparse import errno import os -from io import open as io_open from collections import OrderedDict +from io import open as io_open from textwrap import dedent from typing import Any, MutableMapping, Optional diff --git a/synapse/config/registration.py b/synapse/config/registration.py index 4bf5bbaa17..1a44b17589 100644 --- a/synapse/config/registration.py +++ b/synapse/config/registration.py @@ -162,9 +162,9 @@ class RegistrationConfig(Config): self.replicate_user_profiles_to = [self.replicate_user_profiles_to] self.shadow_server = config.get("shadow_server", None) - self.rewrite_identity_server_urls = config.get( - "rewrite_identity_server_urls" - ) or {} + self.rewrite_identity_server_urls = ( + config.get("rewrite_identity_server_urls") or {} + ) self.disable_msisdn_registration = config.get( "disable_msisdn_registration", False diff --git a/synapse/events/spamcheck.py b/synapse/events/spamcheck.py index 6e6d75bdcb..ae33b3f65d 100644 --- a/synapse/events/spamcheck.py +++ b/synapse/events/spamcheck.py @@ -15,7 +15,7 @@ # limitations under the License. import inspect -from typing import Dict, Optional, List +from typing import Dict, List, Optional from synapse.spam_checker_api import SpamCheckerApi diff --git a/synapse/handlers/account_validity.py b/synapse/handlers/account_validity.py index 72baee44c3..a6c907b9c9 100644 --- a/synapse/handlers/account_validity.py +++ b/synapse/handlers/account_validity.py @@ -93,7 +93,9 @@ class AccountValidityHandler(object): # If account_validity is enabled,check every hour to remove expired users from # the user directory if self._account_validity.enabled: - self.clock.looping_call(self._mark_expired_users_as_inactive, 60 * 60 * 1000) + self.clock.looping_call( + self._mark_expired_users_as_inactive, 60 * 60 * 1000 + ) async def _send_renewal_emails(self): """Gets the list of users whose account is expiring in the amount of time diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index 5d686ab2c9..ebdc239fff 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -412,8 +412,7 @@ class FederationHandler(BaseHandler): # First though we need to fetch all the events that are in # state_map, so we can build up the state below. evs = await self.store.get_events( - list(state_map.values()), - get_prev_content=False, + list(state_map.values()), get_prev_content=False, ) event_map.update(evs) diff --git a/synapse/handlers/identity.py b/synapse/handlers/identity.py index e8a6cf7788..1d07361661 100644 --- a/synapse/handlers/identity.py +++ b/synapse/handlers/identity.py @@ -172,9 +172,7 @@ class IdentityHandler(BaseHandler): bind_data = {"sid": sid, "client_secret": client_secret, "mxid": mxid} if use_v2: bind_url = "%s/_matrix/identity/v2/3pid/bind" % (id_server_url,) - headers["Authorization"] = create_id_access_token_header( - id_access_token - ) + headers["Authorization"] = create_id_access_token_header(id_access_token) else: bind_url = "%s/_matrix/identity/api/v1/3pid/bind" % (id_server_url,) @@ -417,7 +415,9 @@ class IdentityHandler(BaseHandler): if add_https: rewritten_url = "https://" + rewritten_url - rewritten_url = self.rewrite_identity_server_urls.get(rewritten_url, rewritten_url) + rewritten_url = self.rewrite_identity_server_urls.get( + rewritten_url, rewritten_url + ) logger.debug("Rewriting identity server rule from %s to %s", url, rewritten_url) return rewritten_url @@ -463,7 +463,8 @@ class IdentityHandler(BaseHandler): try: data = yield self.http_client.post_json_get_json( - "%s/_matrix/identity/api/v1/validate/email/requestToken" % (id_server_url,), + "%s/_matrix/identity/api/v1/validate/email/requestToken" + % (id_server_url,), params, ) return data @@ -520,7 +521,8 @@ class IdentityHandler(BaseHandler): id_server_url = self.rewrite_id_server_url(id_server_url) try: data = yield self.http_client.post_json_get_json( - "%s/_matrix/identity/api/v1/validate/msisdn/requestToken" % (id_server_url,), + "%s/_matrix/identity/api/v1/validate/msisdn/requestToken" + % (id_server_url,), params, ) except HttpResponseException as e: @@ -806,7 +808,7 @@ class IdentityHandler(BaseHandler): 400, "Non-dict object from %s during v2 hash_details request: %s" % (id_server_url, hash_details), - ) + ) # Extract information from hash_details supported_lookup_algorithms = hash_details.get("algorithms") @@ -821,7 +823,7 @@ class IdentityHandler(BaseHandler): 400, "Invalid hash details received from identity server %s: %s" % (id_server_url, hash_details), - ) + ) # Check if any of the supported lookup algorithms are present if LookupAlgorithm.SHA256 in supported_lookup_algorithms: @@ -863,7 +865,7 @@ class IdentityHandler(BaseHandler): "pepper": lookup_pepper, }, headers=headers, - ) + ) except TimeoutError: raise SynapseError(500, "Timed out contacting identity server") except Exception as e: @@ -1011,9 +1013,7 @@ class IdentityHandler(BaseHandler): raise SynapseError(500, "Timed out contacting identity server") except HttpResponseException as e: logger.warning( - "Error trying to call /store-invite on %s: %s", - id_server_url, - e, + "Error trying to call /store-invite on %s: %s", id_server_url, e, ) if data is None: diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py index 85635f1a0f..34b876b6af 100644 --- a/synapse/handlers/register.py +++ b/synapse/handlers/register.py @@ -619,10 +619,7 @@ class RegistrationHandler(BaseHandler): @defer.inlineCallbacks def post_registration_actions( - self, - user_id, - auth_result, - access_token, + self, user_id, auth_result, access_token, ): """A user has completed registration @@ -654,7 +651,8 @@ class RegistrationHandler(BaseHandler): # Bind the 3PID to the identity server logger.debug( "Binding email to %s on id_server %s", - user_id, self.hs.config.account_threepid_delegate_email, + user_id, + self.hs.config.account_threepid_delegate_email, ) threepid_creds = threepid["threepid_creds"] @@ -662,7 +660,9 @@ class RegistrationHandler(BaseHandler): # `bind_threepid` will add https:// to it, so this restricts # account_threepid_delegate.email to https:// addresses only # We assume this is always the case for dinsic however. - if self.hs.config.account_threepid_delegate_email.startswith("https://"): + if self.hs.config.account_threepid_delegate_email.startswith( + "https://" + ): id_server = self.hs.config.account_threepid_delegate_email[8:] else: # Must start with http:// instead diff --git a/synapse/handlers/room_member.py b/synapse/handlers/room_member.py index 2d9ff97324..cddc95413a 100644 --- a/synapse/handlers/room_member.py +++ b/synapse/handlers/room_member.py @@ -24,16 +24,8 @@ from twisted.internet import defer from synapse import types from synapse.api.constants import EventTypes, Membership -from synapse.api.ratelimiting import Ratelimiter -from synapse.api.errors import ( - AuthError, - Codes, - HttpResponseException, - SynapseError, -) -from synapse.handlers.identity import LookupAlgorithm, create_id_access_token_header -from synapse.http.client import SimpleHttpClient from synapse.api.errors import AuthError, Codes, SynapseError +from synapse.api.ratelimiting import Ratelimiter from synapse.types import Collection, RoomID, UserID from synapse.util.async_helpers import Linearizer from synapse.util.distributor import user_joined_room, user_left_room diff --git a/synapse/rest/client/v2_alpha/account.py b/synapse/rest/client/v2_alpha/account.py index fbc5aa13f3..7d2cd29a60 100644 --- a/synapse/rest/client/v2_alpha/account.py +++ b/synapse/rest/client/v2_alpha/account.py @@ -31,10 +31,10 @@ from synapse.http.servlet import ( parse_json_object_from_request, parse_string, ) -from synapse.types import UserID from synapse.push.mailer import Mailer, load_jinja2_templates +from synapse.types import UserID from synapse.util.msisdn import phone_number_to_msisdn -from synapse.util.stringutils import assert_valid_client_secret, random_string +from synapse.util.stringutils import assert_valid_client_secret from synapse.util.threepids import check_3pid_allowed from ._base import client_patterns, interactive_auth_handler @@ -650,7 +650,10 @@ class ThreepidRestServlet(RestServlet): threepid = body.get("threepid") await self.auth_handler.add_threepid( - user_id, threepid["medium"], threepid["address"], threepid["validated_at"] + user_id, + threepid["medium"], + threepid["address"], + threepid["validated_at"], ) if self.hs.config.shadow_server: @@ -710,7 +713,7 @@ class ThreepidRestServlet(RestServlet): "%s/_matrix/client/r0/account/3pid?access_token=%s&user_id=%s" % (shadow_hs_url, as_token, user_id), body, - ) + ) class ThreepidAddRestServlet(RestServlet): diff --git a/synapse/rest/client/v2_alpha/account_data.py b/synapse/rest/client/v2_alpha/account_data.py index 17495f020b..11d7406040 100644 --- a/synapse/rest/client/v2_alpha/account_data.py +++ b/synapse/rest/client/v2_alpha/account_data.py @@ -15,8 +15,6 @@ import logging -from twisted.internet import defer - from synapse.api.errors import AuthError, NotFoundError, SynapseError from synapse.http.servlet import RestServlet, parse_json_object_from_request from synapse.types import UserID diff --git a/synapse/rest/client/versions.py b/synapse/rest/client/versions.py index c1e5560565..c99250c2ee 100644 --- a/synapse/rest/client/versions.py +++ b/synapse/rest/client/versions.py @@ -54,7 +54,7 @@ class VersionsRestServlet(RestServlet): "unstable_features": { # as per MSC2190, as amended by MSC2264 # to be removed in r0.6.0 - #"m.id_access_token": True, + # "m.id_access_token": True, # Advertise to clients that they need not include an `id_server` # parameter during registration or password reset, as Synapse now decides # itself which identity server to use (or none at all). @@ -64,14 +64,14 @@ class VersionsRestServlet(RestServlet): # also requires `id_server`. If the homeserver is handling 3PID # verification itself, there is no need to ask the user for `id_server` to # be supplied. - #"m.require_identity_server": False, + # "m.require_identity_server": False, # as per MSC2290 - #"m.separate_add_and_bind": True, + # "m.separate_add_and_bind": True, # Implements support for label-based filtering as described in # MSC2326. "org.matrix.label_based_filtering": True, # Implements support for cross signing as described in MSC1756 - #"org.matrix.e2e_cross_signing": True, + # "org.matrix.e2e_cross_signing": True, # Implements additional endpoints as described in MSC2432 "org.matrix.msc2432": True, # Tchap does not currently assume this rule for r0.5.0 diff --git a/synapse/storage/data_stores/main/profile.py b/synapse/storage/data_stores/main/profile.py index 2903de478e..f438dd38be 100644 --- a/synapse/storage/data_stores/main/profile.py +++ b/synapse/storage/data_stores/main/profile.py @@ -17,8 +17,6 @@ from twisted.internet import defer from synapse.api.errors import StoreError - -from synapse.storage import background_updates from synapse.storage._base import SQLBaseStore from synapse.storage.data_stores.main.roommember import ProfileInfo from synapse.util.caches.descriptors import cached diff --git a/tests/http/federation/test_matrix_federation_agent.py b/tests/http/federation/test_matrix_federation_agent.py index ea52330c8e..b1482db39a 100644 --- a/tests/http/federation/test_matrix_federation_agent.py +++ b/tests/http/federation/test_matrix_federation_agent.py @@ -32,9 +32,7 @@ from twisted.web.iweb import IPolicyForHTTPS from synapse.config.homeserver import HomeServerConfig from synapse.crypto.context_factory import FederationPolicyForHTTPS -from synapse.http.federation.matrix_federation_agent import ( - MatrixFederationAgent, -) +from synapse.http.federation.matrix_federation_agent import MatrixFederationAgent from synapse.http.federation.srv_resolver import Server from synapse.http.federation.well_known_resolver import ( WellKnownResolver, diff --git a/tests/rest/client/test_identity.py b/tests/rest/client/test_identity.py index e163a46f6b..4224b0a92e 100644 --- a/tests/rest/client/test_identity.py +++ b/tests/rest/client/test_identity.py @@ -120,9 +120,7 @@ class IdentityEnabledTestCase(unittest.HomeserverTestCase): # TODO: This class does not use a singleton to get it's http client # This should be fixed for easier testing # https://github.com/matrix-org/synapse-dinsic/issues/26 - self.hs.get_handlers().identity_handler.http_client = ( - mock_http_client - ) + self.hs.get_handlers().identity_handler.http_client = mock_http_client return self.hs @@ -142,8 +140,8 @@ class IdentityEnabledTestCase(unittest.HomeserverTestCase): self.hs.get_room_member_handler().simple_http_client = Mock( spec=["get_json", "post_json_get_json"] ) - self.hs.get_room_member_handler().simple_http_client.get_json.return_value = ( - defer.succeed((200, "{}")) + self.hs.get_room_member_handler().simple_http_client.get_json.return_value = defer.succeed( + (200, "{}") ) params = { diff --git a/tests/rest/client/test_room_access_rules.py b/tests/rest/client/test_room_access_rules.py index f10ae0adeb..7da0ef4e18 100644 --- a/tests/rest/client/test_room_access_rules.py +++ b/tests/rest/client/test_room_access_rules.py @@ -21,6 +21,7 @@ import string from mock import Mock from twisted.internet import defer + from synapse.api.constants import EventTypes, JoinRules, RoomCreationPreset from synapse.rest import admin from synapse.rest.client.v1 import login, room @@ -83,9 +84,7 @@ class RoomAccessTestCase(unittest.HomeserverTestCase): mock_federation_client = Mock(spec=["send_invite"]) mock_federation_client.send_invite.side_effect = send_invite - mock_http_client = Mock( - spec=["get_json", "post_json_get_json"], - ) + mock_http_client = Mock(spec=["get_json", "post_json_get_json"],) # Mocking the response for /info on the IS API. mock_http_client.get_json.side_effect = get_json # Mocking the response for /store-invite on the IS API. @@ -99,7 +98,9 @@ class RoomAccessTestCase(unittest.HomeserverTestCase): # TODO: This class does not use a singleton to get it's http client # This should be fixed for easier testing # https://github.com/matrix-org/synapse-dinsic/issues/26 - self.hs.get_handlers().identity_handler.blacklisting_http_client = mock_http_client + self.hs.get_handlers().identity_handler.blacklisting_http_client = ( + mock_http_client + ) return self.hs