Code style fixes.
This commit is contained in:
parent
8b1dd9f57f
commit
acb68a39e0
|
@ -111,6 +111,7 @@ class NotFoundError(SynapseError):
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class AuthError(SynapseError):
|
class AuthError(SynapseError):
|
||||||
"""An error raised when there was a problem authorising an event."""
|
"""An error raised when there was a problem authorising an event."""
|
||||||
|
|
||||||
|
|
|
@ -236,8 +236,7 @@ class Pusher(object):
|
||||||
# of old notifications.
|
# of old notifications.
|
||||||
logger.warn("Giving up on a notification to user %s, "
|
logger.warn("Giving up on a notification to user %s, "
|
||||||
"pushkey %s",
|
"pushkey %s",
|
||||||
self.user_name, self.pushkey
|
self.user_name, self.pushkey)
|
||||||
)
|
|
||||||
self.backoff_delay = Pusher.INITIAL_BACKOFF
|
self.backoff_delay = Pusher.INITIAL_BACKOFF
|
||||||
self.last_token = chunk['end']
|
self.last_token = chunk['end']
|
||||||
self.store.update_pusher_last_token(
|
self.store.update_pusher_last_token(
|
||||||
|
@ -258,8 +257,7 @@ class Pusher(object):
|
||||||
"Trying again in %dms",
|
"Trying again in %dms",
|
||||||
self.user_name,
|
self.user_name,
|
||||||
self.clock.time_msec() - self.failing_since,
|
self.clock.time_msec() - self.failing_since,
|
||||||
self.backoff_delay
|
self.backoff_delay)
|
||||||
)
|
|
||||||
yield synapse.util.async.sleep(self.backoff_delay / 1000.0)
|
yield synapse.util.async.sleep(self.backoff_delay / 1000.0)
|
||||||
self.backoff_delay *= 2
|
self.backoff_delay *= 2
|
||||||
if self.backoff_delay > Pusher.MAX_BACKOFF:
|
if self.backoff_delay > Pusher.MAX_BACKOFF:
|
||||||
|
@ -299,7 +297,6 @@ class Pusher(object):
|
||||||
self.has_unread = False
|
self.has_unread = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _value_for_dotted_key(dotted_key, event):
|
def _value_for_dotted_key(dotted_key, event):
|
||||||
parts = dotted_key.split(".")
|
parts = dotted_key.split(".")
|
||||||
val = event
|
val = event
|
||||||
|
@ -310,6 +307,7 @@ def _value_for_dotted_key(dotted_key, event):
|
||||||
parts = parts[1:]
|
parts = parts[1:]
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
|
||||||
def _tweaks_for_actions(actions):
|
def _tweaks_for_actions(actions):
|
||||||
tweaks = {}
|
tweaks = {}
|
||||||
for a in actions:
|
for a in actions:
|
||||||
|
@ -319,6 +317,7 @@ def _tweaks_for_actions(actions):
|
||||||
tweaks['sound'] = a['set_sound']
|
tweaks['sound'] = a['set_sound']
|
||||||
return tweaks
|
return tweaks
|
||||||
|
|
||||||
|
|
||||||
class PusherConfigException(Exception):
|
class PusherConfigException(Exception):
|
||||||
def __init__(self, msg):
|
def __init__(self, msg):
|
||||||
super(PusherConfigException, self).__init__(msg)
|
super(PusherConfigException, self).__init__(msg)
|
|
@ -30,7 +30,7 @@ class PushRuleRestServlet(ClientV1RestServlet):
|
||||||
'sender': 1,
|
'sender': 1,
|
||||||
'room': 2,
|
'room': 2,
|
||||||
'content': 3,
|
'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 = (
|
SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR = (
|
||||||
|
@ -260,7 +260,9 @@ class PushRuleRestServlet(ClientV1RestServlet):
|
||||||
|
|
||||||
if path == []:
|
if path == []:
|
||||||
# we're a reference impl: pedantry is our job.
|
# 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] == '':
|
if path[0] == '':
|
||||||
defer.returnValue((200, rules))
|
defer.returnValue((200, rules))
|
||||||
|
@ -271,7 +273,9 @@ class PushRuleRestServlet(ClientV1RestServlet):
|
||||||
elif path[0] == 'device':
|
elif path[0] == 'device':
|
||||||
path = path[1:]
|
path = path[1:]
|
||||||
if path == []:
|
if path == []:
|
||||||
raise UnrecognizedRequestError(PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR)
|
raise UnrecognizedRequestError(
|
||||||
|
PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR
|
||||||
|
)
|
||||||
if path[0] == '':
|
if path[0] == '':
|
||||||
defer.returnValue((200, rules['device']))
|
defer.returnValue((200, rules['device']))
|
||||||
|
|
||||||
|
@ -290,11 +294,13 @@ class PushRuleRestServlet(ClientV1RestServlet):
|
||||||
def on_OPTIONS(self, _):
|
def on_OPTIONS(self, _):
|
||||||
return 200, {}
|
return 200, {}
|
||||||
|
|
||||||
|
|
||||||
def _add_empty_priority_class_arrays(d):
|
def _add_empty_priority_class_arrays(d):
|
||||||
for pc in PushRuleRestServlet.PRIORITY_CLASS_MAP.keys():
|
for pc in PushRuleRestServlet.PRIORITY_CLASS_MAP.keys():
|
||||||
d[pc] = []
|
d[pc] = []
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
def _instance_handle_from_conditions(conditions):
|
def _instance_handle_from_conditions(conditions):
|
||||||
"""
|
"""
|
||||||
Given a list of conditions, return the instance handle of the
|
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 c['instance_handle']
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _filter_ruleset_with_path(ruleset, path):
|
def _filter_ruleset_with_path(ruleset, path):
|
||||||
if path == []:
|
if path == []:
|
||||||
raise UnrecognizedRequestError(PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR)
|
raise UnrecognizedRequestError(
|
||||||
|
PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR
|
||||||
|
)
|
||||||
|
|
||||||
if path[0] == '':
|
if path[0] == '':
|
||||||
return ruleset
|
return ruleset
|
||||||
|
@ -316,7 +325,9 @@ def _filter_ruleset_with_path(ruleset, path):
|
||||||
raise UnrecognizedRequestError()
|
raise UnrecognizedRequestError()
|
||||||
path = path[1:]
|
path = path[1:]
|
||||||
if path == []:
|
if path == []:
|
||||||
raise UnrecognizedRequestError(PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR)
|
raise UnrecognizedRequestError(
|
||||||
|
PushRuleRestServlet.SLIGHTLY_PEDANTIC_TRAILING_SLASH_ERROR
|
||||||
|
)
|
||||||
if path[0] == '':
|
if path[0] == '':
|
||||||
return ruleset[template_kind]
|
return ruleset[template_kind]
|
||||||
rule_id = path[0]
|
rule_id = path[0]
|
||||||
|
@ -325,6 +336,7 @@ def _filter_ruleset_with_path(ruleset, path):
|
||||||
return r
|
return r
|
||||||
raise NotFoundError
|
raise NotFoundError
|
||||||
|
|
||||||
|
|
||||||
def _priority_class_from_spec(spec):
|
def _priority_class_from_spec(spec):
|
||||||
if spec['template'] not in PushRuleRestServlet.PRIORITY_CLASS_MAP.keys():
|
if spec['template'] not in PushRuleRestServlet.PRIORITY_CLASS_MAP.keys():
|
||||||
raise InvalidRuleException("Unknown template: %s" % (spec['kind']))
|
raise InvalidRuleException("Unknown template: %s" % (spec['kind']))
|
||||||
|
@ -335,6 +347,7 @@ def _priority_class_from_spec(spec):
|
||||||
|
|
||||||
return pc
|
return pc
|
||||||
|
|
||||||
|
|
||||||
def _priority_class_to_template_name(pc):
|
def _priority_class_to_template_name(pc):
|
||||||
if pc > PushRuleRestServlet.PRIORITY_CLASS_MAP['override']:
|
if pc > PushRuleRestServlet.PRIORITY_CLASS_MAP['override']:
|
||||||
# per-device
|
# per-device
|
||||||
|
@ -343,6 +356,7 @@ def _priority_class_to_template_name(pc):
|
||||||
else:
|
else:
|
||||||
return PushRuleRestServlet.PRIORITY_CLASS_INVERSE_MAP[pc]
|
return PushRuleRestServlet.PRIORITY_CLASS_INVERSE_MAP[pc]
|
||||||
|
|
||||||
|
|
||||||
def _rule_to_template(rule):
|
def _rule_to_template(rule):
|
||||||
template_name = _priority_class_to_template_name(rule['priority_class'])
|
template_name = _priority_class_to_template_name(rule['priority_class'])
|
||||||
if template_name in ['override', 'underride']:
|
if template_name in ['override', 'underride']:
|
||||||
|
@ -359,6 +373,7 @@ def _rule_to_template(rule):
|
||||||
ret["pattern"] = thecond["pattern"]
|
ret["pattern"] = thecond["pattern"]
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def _strip_device_condition(rule):
|
def _strip_device_condition(rule):
|
||||||
for i, c in enumerate(rule['conditions']):
|
for i, c in enumerate(rule['conditions']):
|
||||||
if c['kind'] == 'device':
|
if c['kind'] == 'device':
|
||||||
|
|
|
@ -146,7 +146,8 @@ class PushRuleStore(SQLBaseStore):
|
||||||
|
|
||||||
txn.execute(sql, new_rule.values())
|
txn.execute(sql, new_rule.values())
|
||||||
|
|
||||||
def _add_push_rule_highest_priority_txn(self, txn, user_name, priority_class, **kwargs):
|
def _add_push_rule_highest_priority_txn(self, txn, user_name,
|
||||||
|
priority_class, **kwargs):
|
||||||
# find the highest priority rule in that class
|
# find the highest priority rule in that class
|
||||||
sql = (
|
sql = (
|
||||||
"SELECT COUNT(*), MAX(priority) FROM " + PushRuleTable.table_name +
|
"SELECT COUNT(*), MAX(priority) FROM " + PushRuleTable.table_name +
|
||||||
|
|
Loading…
Reference in New Issue