summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-02-10 16:30:48 +0000
committerMark Haines <mark.haines@matrix.org>2015-02-10 16:30:48 +0000
commitb085fac7353e1cd395b89f9334c8273a8e996f48 (patch)
tree140b1a6279527dbcb5b81dbd392d75777b5b3e8a
parentSign auth_chains when returned by /state/ requests (diff)
downloadsynapse-b085fac7353e1cd395b89f9334c8273a8e996f48.tar.xz
Code-style fixes
-rw-r--r--synapse/handlers/presence.py4
-rw-r--r--synapse/handlers/register.py13
-rw-r--r--synapse/push/__init__.py8
-rw-r--r--synapse/push/baserules.py11
-rw-r--r--synapse/push/rulekinds.py12
-rw-r--r--synapse/python_dependencies.py6
-rw-r--r--synapse/rest/client/v1/push_rule.py18
-rw-r--r--synapse/rest/client/v1/pusher.py4
-rw-r--r--synapse/rest/media/v1/upload_resource.py7
-rw-r--r--synapse/storage/_base.py6
-rw-r--r--synapse/storage/push_rule.py4
11 files changed, 57 insertions, 36 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py
index cd0798c2b0..6a266ee0fe 100644
--- a/synapse/handlers/presence.py
+++ b/synapse/handlers/presence.py
@@ -658,7 +658,9 @@ class PresenceHandler(BaseHandler):
 
             observers = set(self._remote_recvmap.get(user, set()))
             if observers:
-                logger.debug(" | %d interested local observers %r", len(observers), observers)
+                logger.debug(
+                    " | %d interested local observers %r", len(observers), observers
+                )
 
             rm_handler = self.homeserver.get_handlers().room_member_handler
             room_ids = yield rm_handler.get_rooms_for_user(user)
diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py
index 4f06c487b1..0247327eb9 100644
--- a/synapse/handlers/register.py
+++ b/synapse/handlers/register.py
@@ -105,17 +105,20 @@ class RegistrationHandler(BaseHandler):
         # do it here.
         try:
             auth_user = UserID.from_string(user_id)
-            identicon_resource = self.hs.get_resource_for_media_repository().getChildWithDefault("identicon", None)
-            upload_resource = self.hs.get_resource_for_media_repository().getChildWithDefault("upload", None)
+            media_repository = self.hs.get_resource_for_media_repository()
+            identicon_resource = media_repository.getChildWithDefault("identicon", None)
+            upload_resource = media_repository.getChildWithDefault("upload", None)
             identicon_bytes = identicon_resource.generate_identicon(user_id, 320, 320)
             content_uri = yield upload_resource.create_content(
                 "image/png", None, identicon_bytes, len(identicon_bytes), auth_user
             )
             profile_handler = self.hs.get_handlers().profile_handler
-            profile_handler.set_avatar_url(auth_user, auth_user, ("%s#auto" % content_uri))
+            profile_handler.set_avatar_url(
+                auth_user, auth_user, ("%s#auto" % (content_uri,))
+            )
         except NotImplementedError:
-            pass # make tests pass without messing around creating default avatars
-        
+            pass  # make tests pass without messing around creating default avatars
+
         defer.returnValue((user_id, token))
 
     @defer.inlineCallbacks
diff --git a/synapse/push/__init__.py b/synapse/push/__init__.py
index 6f143a5df9..418a348a58 100644
--- a/synapse/push/__init__.py
+++ b/synapse/push/__init__.py
@@ -140,7 +140,7 @@ class Pusher(object):
                    lambda x: ('[%s%s]' % (x.group(1) and '^' or '',
                                           re.sub(r'\\\-', '-', x.group(2)))), r)
         return r
-    
+
     def _event_fulfills_condition(self, ev, condition, display_name, room_member_count):
         if condition['kind'] == 'event_match':
             if 'pattern' not in condition:
@@ -170,8 +170,10 @@ class Pusher(object):
                 return False
             if not display_name:
                 return False
-            return re.search("\b%s\b" % re.escape(display_name),
-                            ev['content']['body'], flags=re.IGNORECASE) is not None
+            return re.search(
+                "\b%s\b" % re.escape(display_name), ev['content']['body'],
+                flags=re.IGNORECASE
+            ) is not None
 
         elif condition['kind'] == 'room_member_count':
             if 'is' not in condition:
diff --git a/synapse/push/baserules.py b/synapse/push/baserules.py
index 37878f1e0b..162d265f66 100644
--- a/synapse/push/baserules.py
+++ b/synapse/push/baserules.py
@@ -1,5 +1,6 @@
 from synapse.push.rulekinds import PRIORITY_CLASS_MAP, PRIORITY_CLASS_INVERSE_MAP
 
+
 def list_with_base_rules(rawrules, user_name):
     ruleslist = []
 
@@ -9,9 +10,9 @@ def list_with_base_rules(rawrules, user_name):
         if r['priority_class'] < current_prio_class:
             while r['priority_class'] < current_prio_class:
                 ruleslist.extend(make_base_rules(
-                        user_name,
-                        PRIORITY_CLASS_INVERSE_MAP[current_prio_class])
-                    )
+                    user_name,
+                    PRIORITY_CLASS_INVERSE_MAP[current_prio_class]
+                ))
                 current_prio_class -= 1
 
         ruleslist.append(r)
@@ -19,8 +20,8 @@ def list_with_base_rules(rawrules, user_name):
     while current_prio_class > 0:
         ruleslist.extend(make_base_rules(
             user_name,
-            PRIORITY_CLASS_INVERSE_MAP[current_prio_class])
-        )
+            PRIORITY_CLASS_INVERSE_MAP[current_prio_class]
+        ))
         current_prio_class -= 1
 
     return ruleslist
diff --git a/synapse/push/rulekinds.py b/synapse/push/rulekinds.py
index 763bdee58e..660aa4e10e 100644
--- a/synapse/push/rulekinds.py
+++ b/synapse/push/rulekinds.py
@@ -1,8 +1,8 @@
 PRIORITY_CLASS_MAP = {
-        'underride': 1,
-        'sender': 2,
-        'room': 3,
-        'content': 4,
-        'override': 5,
-    }
+    'underride': 1,
+    'sender': 2,
+    'room': 3,
+    'content': 4,
+    'override': 5,
+}
 PRIORITY_CLASS_INVERSE_MAP = {v: k for k, v in PRIORITY_CLASS_MAP.items()}
diff --git a/synapse/python_dependencies.py b/synapse/python_dependencies.py
index a89d618606..fd68da9dfb 100644
--- a/synapse/python_dependencies.py
+++ b/synapse/python_dependencies.py
@@ -19,10 +19,11 @@ REQUIREMENTS = {
     "pydenticon": ["pydenticon"],
 }
 
+
 def github_link(project, version, egg):
     return "https://github.com/%s/tarball/%s/#egg=%s" % (project, version, egg)
 
-DEPENDENCY_LINKS=[
+DEPENDENCY_LINKS = [
     github_link(
         project="matrix-org/syutil",
         version="v0.0.2",
@@ -101,6 +102,7 @@ def check_requirements():
                         % (dependency, file_path, version, required_version)
                     )
 
+
 def list_requirements():
     result = []
     linked = []
@@ -111,7 +113,7 @@ def list_requirements():
     for requirement in REQUIREMENTS:
         is_linked = False
         for link in linked:
-            if requirement.replace('-','_').startswith(link):
+            if requirement.replace('-', '_').startswith(link):
                 is_linked = True
         if not is_linked:
             result.append(requirement)
diff --git a/synapse/rest/client/v1/push_rule.py b/synapse/rest/client/v1/push_rule.py
index d43ade39dd..c4e7dfcf0e 100644
--- a/synapse/rest/client/v1/push_rule.py
+++ b/synapse/rest/client/v1/push_rule.py
@@ -15,12 +15,17 @@
 
 from twisted.internet import defer
 
-from synapse.api.errors import SynapseError, Codes, UnrecognizedRequestError, NotFoundError, \
-    StoreError
+from synapse.api.errors import (
+    SynapseError, Codes, UnrecognizedRequestError, NotFoundError, StoreError
+)
 from .base import ClientV1RestServlet, client_path_pattern
-from synapse.storage.push_rule import InconsistentRuleException, RuleNotFoundException
+from synapse.storage.push_rule import (
+    InconsistentRuleException, RuleNotFoundException
+)
 import synapse.push.baserules as baserules
-from synapse.push.rulekinds import PRIORITY_CLASS_MAP, PRIORITY_CLASS_INVERSE_MAP
+from synapse.push.rulekinds import (
+    PRIORITY_CLASS_MAP, PRIORITY_CLASS_INVERSE_MAP
+)
 
 import json
 
@@ -105,7 +110,9 @@ class PushRuleRestServlet(ClientV1RestServlet):
         # we build up the full structure and then decide which bits of it
         # to send which means doing unnecessary work sometimes but is
         # is probably not going to make a whole lot of difference
-        rawrules = yield self.hs.get_datastore().get_push_rules_for_user_name(user.to_string())
+        rawrules = yield self.hs.get_datastore().get_push_rules_for_user_name(
+            user.to_string()
+        )
 
         for r in rawrules:
             r["conditions"] = json.loads(r["conditions"])
@@ -383,6 +390,7 @@ def _namespaced_rule_id_from_spec(spec):
 def _rule_id_from_namespaced(in_rule_id):
     return in_rule_id.split('/')[-1]
 
+
 class InvalidRuleException(Exception):
     pass
 
diff --git a/synapse/rest/client/v1/pusher.py b/synapse/rest/client/v1/pusher.py
index e10d2576d2..80e9939b79 100644
--- a/synapse/rest/client/v1/pusher.py
+++ b/synapse/rest/client/v1/pusher.py
@@ -34,8 +34,8 @@ class PusherRestServlet(ClientV1RestServlet):
         pusher_pool = self.hs.get_pusherpool()
 
         if ('pushkey' in content and 'app_id' in content
-                    and 'kind' in content and
-                    content['kind'] is None):
+                and 'kind' in content and
+                content['kind'] is None):
             yield pusher_pool.remove_pusher(
                 content['app_id'], content['pushkey']
             )
diff --git a/synapse/rest/media/v1/upload_resource.py b/synapse/rest/media/v1/upload_resource.py
index 5b42782331..6df52ca434 100644
--- a/synapse/rest/media/v1/upload_resource.py
+++ b/synapse/rest/media/v1/upload_resource.py
@@ -38,9 +38,10 @@ class UploadResource(BaseMediaResource):
     def render_OPTIONS(self, request):
         respond_with_json(request, 200, {}, send_cors=True)
         return NOT_DONE_YET
-        
+
     @defer.inlineCallbacks
-    def create_content(self, media_type, upload_name, content, content_length, auth_user):
+    def create_content(self, media_type, upload_name, content, content_length,
+                       auth_user):
         media_id = random_string(24)
 
         fname = self.filepaths.local_media_filepath(media_id)
@@ -65,7 +66,7 @@ class UploadResource(BaseMediaResource):
         }
 
         yield self._generate_local_thumbnails(media_id, media_info)
-        
+
         defer.returnValue("mxc://%s/%s" % (self.server_name, media_id))
 
     @defer.inlineCallbacks
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index 36455ef93c..3e1ab0a159 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -84,7 +84,7 @@ class PerformanceCounters(object):
 
     def update(self, key, start_time, end_time=None):
         if end_time is None:
-            end_time = time.time() * 1000;
+            end_time = time.time() * 1000
         duration = end_time - start_time
         count, cum_time = self.current_counters.get(key, (0, 0))
         count += 1
@@ -588,7 +588,7 @@ class SQLBaseStore(object):
             "LIMIT 1 "
         )
 
-        start_time = time.time() * 1000;
+        start_time = time.time() * 1000
 
         txn.execute(sql, (event_id,))
 
@@ -613,7 +613,7 @@ class SQLBaseStore(object):
     def _get_event_from_row_txn(self, txn, internal_metadata, js, redacted,
                                 check_redacted=True, get_prev_content=False):
 
-        start_time = time.time() * 1000;
+        start_time = time.time() * 1000
         update_counter = self._get_event_counters.update
 
         d = json.loads(js)
diff --git a/synapse/storage/push_rule.py b/synapse/storage/push_rule.py
index 30e23445d9..620de71398 100644
--- a/synapse/storage/push_rule.py
+++ b/synapse/storage/push_rule.py
@@ -91,7 +91,9 @@ class PushRuleStore(SQLBaseStore):
         txn.execute(sql, (user_name, relative_to_rule))
         res = txn.fetchall()
         if not res:
-            raise RuleNotFoundException("before/after rule not found: %s" % (relative_to_rule))
+            raise RuleNotFoundException(
+                "before/after rule not found: %s" % (relative_to_rule,)
+            )
         priority_class, base_rule_priority = res[0]
 
         if 'priority_class' in kwargs and kwargs['priority_class'] != priority_class: