apply linting
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user