summary refs log tree commit diff
path: root/synapse/rest/client/v1/push_rule.py
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-01-29 16:10:35 +0000
committerMark Haines <mark.haines@matrix.org>2015-01-29 16:12:40 +0000
commitacb68a39e02f405c116135400e33a3b1940a07f8 (patch)
tree4629354ff9d7091b8073558dc642ee188b16f136 /synapse/rest/client/v1/push_rule.py
parentOnly send a badge-reset if the user actually has unread notifications. (diff)
downloadsynapse-acb68a39e02f405c116135400e33a3b1940a07f8.tar.xz
Code style fixes.
Diffstat (limited to 'synapse/rest/client/v1/push_rule.py')
-rw-r--r--synapse/rest/client/v1/push_rule.py29
1 files changed, 22 insertions, 7 deletions
diff --git a/synapse/rest/client/v1/push_rule.py b/synapse/rest/client/v1/push_rule.py
index 64743a2f46..2b1e930326 100644
--- a/synapse/rest/client/v1/push_rule.py
+++ b/synapse/rest/client/v1/push_rule.py
@@ -30,9 +30,9 @@ class PushRuleRestServlet(ClientV1RestServlet):
         'sender': 1,
         'room': 2,
         'content': 3,
-        'override': 4
+        'override': 4,
     }
-    PRIORITY_CLASS_INVERSE_MAP = {v: k for k,v in PRIORITY_CLASS_MAP.items()}
+    PRIORITY_CLASS_INVERSE_MAP = {v: k for k, v in PRIORITY_CLASS_MAP.items()}
     SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR = (
         "Unrecognised request: You probably wanted a trailing slash")
 
@@ -260,7 +260,9 @@ class PushRuleRestServlet(ClientV1RestServlet):
 
         if path == []:
             # we're a reference impl: pedantry is our job.
-            raise UnrecognizedRequestError(PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR)
+            raise UnrecognizedRequestError(
+                PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR
+            )
 
         if path[0] == '':
             defer.returnValue((200, rules))
@@ -271,7 +273,9 @@ class PushRuleRestServlet(ClientV1RestServlet):
         elif path[0] == 'device':
             path = path[1:]
             if path == []:
-                raise UnrecognizedRequestError(PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR)
+                raise UnrecognizedRequestError(
+                    PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR
+                )
             if path[0] == '':
                 defer.returnValue((200, rules['device']))
 
@@ -290,11 +294,13 @@ class PushRuleRestServlet(ClientV1RestServlet):
     def on_OPTIONS(self, _):
         return 200, {}
 
+
 def _add_empty_priority_class_arrays(d):
     for pc in PushRuleRestServlet.PRIORITY_CLASS_MAP.keys():
         d[pc] = []
     return d
 
+
 def _instance_handle_from_conditions(conditions):
     """
     Given a list of conditions, return the instance handle of the
@@ -305,9 +311,12 @@ def _instance_handle_from_conditions(conditions):
             return c['instance_handle']
     return None
 
+
 def _filter_ruleset_with_path(ruleset, path):
     if path == []:
-        raise UnrecognizedRequestError(PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR)
+        raise UnrecognizedRequestError(
+            PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR
+        )
 
     if path[0] == '':
         return ruleset
@@ -316,7 +325,9 @@ def _filter_ruleset_with_path(ruleset, path):
         raise UnrecognizedRequestError()
     path = path[1:]
     if path == []:
-        raise UnrecognizedRequestError(PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR)
+        raise UnrecognizedRequestError(
+            PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR
+        )
     if path[0] == '':
         return ruleset[template_kind]
     rule_id = path[0]
@@ -325,6 +336,7 @@ def _filter_ruleset_with_path(ruleset, path):
             return r
     raise NotFoundError
 
+
 def _priority_class_from_spec(spec):
     if spec['template'] not in PushRuleRestServlet.PRIORITY_CLASS_MAP.keys():
         raise InvalidRuleException("Unknown template: %s" % (spec['kind']))
@@ -335,6 +347,7 @@ def _priority_class_from_spec(spec):
 
     return pc
 
+
 def _priority_class_to_template_name(pc):
     if pc > PushRuleRestServlet.PRIORITY_CLASS_MAP['override']:
         # per-device
@@ -343,6 +356,7 @@ def _priority_class_to_template_name(pc):
     else:
         return PushRuleRestServlet.PRIORITY_CLASS_INVERSE_MAP[pc]
 
+
 def _rule_to_template(rule):
     template_name = _priority_class_to_template_name(rule['priority_class'])
     if template_name in ['override', 'underride']:
@@ -359,8 +373,9 @@ def _rule_to_template(rule):
         ret["pattern"] = thecond["pattern"]
         return ret
 
+
 def _strip_device_condition(rule):
-    for i,c in enumerate(rule['conditions']):
+    for i, c in enumerate(rule['conditions']):
         if c['kind'] == 'device':
             del rule['conditions'][i]
     return rule