summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2019-08-21 16:27:42 +0200
committerAndrew Morgan <andrew@amorgan.xyz>2019-08-21 16:27:42 +0200
commit24ee3aecd5c67673d33f2ed300fddb2d23daf8c9 (patch)
tree710a5fbd654b4c6e6bdf183c51b3771a9c9c9b15
parentUse the v2 lookup API (diff)
downloadsynapse-24ee3aecd5c67673d33f2ed300fddb2d23daf8c9.tar.xz
lint
-rw-r--r--synapse/handlers/identity.py4
-rw-r--r--synapse/handlers/room_member.py22
-rw-r--r--synapse/server.pyi1
-rw-r--r--synapse/util/hash.py2
4 files changed, 17 insertions, 12 deletions
diff --git a/synapse/handlers/identity.py b/synapse/handlers/identity.py
index beb7cadd46..bddbc03943 100644
--- a/synapse/handlers/identity.py
+++ b/synapse/handlers/identity.py
@@ -18,6 +18,7 @@
 """Utilities for interacting with Identity Servers"""
 
 import logging
+from enum import Enum
 
 from canonicaljson import json
 
@@ -31,7 +32,6 @@ from synapse.api.errors import (
 )
 
 from ._base import BaseHandler
-from enum import Enum
 
 logger = logging.getLogger(__name__)
 
@@ -284,6 +284,7 @@ class IdentityHandler(BaseHandler):
             logger.info("Proxied requestToken failed: %r", e)
             raise e.to_synapse_error()
 
+
 class LookupAlgorithm(Enum):
     """
     Supported hashing algorithms when performing a 3PID lookup.
@@ -292,5 +293,6 @@ class LookupAlgorithm(Enum):
         encoding
     NONE - Not performing any hashing. Simply sending an (address, medium) combo in plaintext
     """
+
     SHA256 = "sha256"
     NONE = "none"
diff --git a/synapse/handlers/room_member.py b/synapse/handlers/room_member.py
index 68b280924d..c175b02974 100644
--- a/synapse/handlers/room_member.py
+++ b/synapse/handlers/room_member.py
@@ -29,6 +29,7 @@ from twisted.internet import defer
 from synapse import types
 from synapse.api.constants import EventTypes, Membership
 from synapse.api.errors import AuthError, Codes, HttpResponseException, SynapseError
+from synapse.handlers.identity import LookupAlgorithm
 from synapse.types import RoomID, UserID
 from synapse.util.async_helpers import Linearizer
 from synapse.util.distributor import user_joined_room, user_left_room
@@ -36,12 +37,11 @@ from synapse.util.hash import sha256_and_url_safe_base64
 
 from ._base import BaseHandler
 
-from synapse.handlers.identity import LookupAlgorithm
-
 logger = logging.getLogger(__name__)
 
 id_server_scheme = "https://"
 
+
 class RoomMemberHandler(object):
     # TODO(paul): This handler currently contains a messy conflation of
     #   low-level API that works on UserID objects and so on, and REST-level
@@ -712,10 +712,14 @@ class RoomMemberHandler(object):
             return None
 
         # Check if none of the supported lookup algorithms are present
-        if not any(i in supported_lookup_algorithms for i in [LookupAlgorithm.SHA256,
-                                                              LookupAlgorithm.NONE]):
-            logger.warn("No supported lookup algorithms found for %s%s" %
-                        (id_server_scheme, id_server))
+        if not any(
+            i in supported_lookup_algorithms
+            for i in [LookupAlgorithm.SHA256, LookupAlgorithm.NONE]
+        ):
+            logger.warn(
+                "No supported lookup algorithms found for %s%s"
+                % (id_server_scheme, id_server)
+            )
 
             return None
 
@@ -748,9 +752,8 @@ class RoomMemberHandler(object):
             return None
 
         # Check for a mapping from what we looked up to an MXID
-        if (
-            "mappings" not in lookup_results
-            or not isinstance(lookup_results["mappings"], dict)
+        if "mappings" not in lookup_results or not isinstance(
+            lookup_results["mappings"], dict
         ):
             logger.debug("No results from 3pid lookup")
             return None
@@ -758,7 +761,6 @@ class RoomMemberHandler(object):
         # Return the MXID if it's available, or None otherwise
         return lookup_results["mappings"].get(lookup_value)
 
-
     @defer.inlineCallbacks
     def _verify_any_signature(self, data, server_hostname):
         if server_hostname not in data["signatures"]:
diff --git a/synapse/server.pyi b/synapse/server.pyi
index 16f8f6b573..b64ed09c04 100644
--- a/synapse/server.pyi
+++ b/synapse/server.pyi
@@ -18,6 +18,7 @@ import synapse.server_notices.server_notices_sender
 import synapse.state
 import synapse.storage
 
+
 class HomeServer(object):
     @property
     def config(self) -> synapse.config.homeserver.HomeServerConfig:
diff --git a/synapse/util/hash.py b/synapse/util/hash.py
index aa5d5ae31c..359168704e 100644
--- a/synapse/util/hash.py
+++ b/synapse/util/hash.py
@@ -15,6 +15,7 @@
 # limitations under the License.
 
 import hashlib
+
 import unpaddedbase64
 
 
@@ -30,4 +31,3 @@ def sha256_and_url_safe_base64(input_text):
     """
     digest = hashlib.sha256(input_text.encode()).digest()
     return unpaddedbase64.encode_base64(digest, urlsafe=True)
-