Put staticmethods at module level

pull/1812/head
Erik Johnston 2017-01-16 15:05:24 +00:00
parent ec0a523ac3
commit beda469bc6
1 changed files with 125 additions and 127 deletions

View File

@ -337,7 +337,7 @@ class StateHandler(object):
for st in state_groups_ids.values() for st in state_groups_ids.values()
] ]
with Measure(self.clock, "state._resolve_events"): with Measure(self.clock, "state._resolve_events"):
new_state, _ = Resolver.resolve_events( new_state, _ = resolve_events(
state_sets, event_type, state_key state_sets, event_type, state_key
) )
new_state = { new_state = {
@ -392,11 +392,11 @@ class StateHandler(object):
) )
with Measure(self.clock, "state._resolve_events"): with Measure(self.clock, "state._resolve_events"):
if event.is_state(): if event.is_state():
return Resolver.resolve_events( return resolve_events(
state_sets, event.type, event.state_key state_sets, event.type, event.state_key
) )
else: else:
return Resolver.resolve_events(state_sets) return resolve_events(state_sets)
def _ordered_events(events): def _ordered_events(events):
@ -406,8 +406,6 @@ def _ordered_events(events):
return sorted(events, key=key_func) return sorted(events, key=key_func)
class Resolver(object):
@staticmethod
def resolve_events(state_sets, event_type=None, state_key=""): def resolve_events(state_sets, event_type=None, state_key=""):
""" """
Returns Returns
@ -448,7 +446,7 @@ class Resolver(object):
} }
try: try:
resolved_state = Resolver._resolve_state_events( resolved_state = _resolve_state_events(
conflicted_state, auth_events conflicted_state, auth_events
) )
except: except:
@ -460,7 +458,7 @@ class Resolver(object):
return new_state, prev_states return new_state, prev_states
@staticmethod
def _resolve_state_events(conflicted_state, auth_events): def _resolve_state_events(conflicted_state, auth_events):
""" This is where we actually decide which of the conflicted state to """ This is where we actually decide which of the conflicted state to
use. use.
@ -476,7 +474,7 @@ class Resolver(object):
if power_key in conflicted_state: if power_key in conflicted_state:
events = conflicted_state[power_key] events = conflicted_state[power_key]
logger.debug("Resolving conflicted power levels %r", events) logger.debug("Resolving conflicted power levels %r", events)
resolved_state[power_key] = Resolver._resolve_auth_events( resolved_state[power_key] = _resolve_auth_events(
events, auth_events) events, auth_events)
auth_events.update(resolved_state) auth_events.update(resolved_state)
@ -484,7 +482,7 @@ class Resolver(object):
for key, events in conflicted_state.items(): for key, events in conflicted_state.items():
if key[0] == EventTypes.JoinRules: if key[0] == EventTypes.JoinRules:
logger.debug("Resolving conflicted join rules %r", events) logger.debug("Resolving conflicted join rules %r", events)
resolved_state[key] = Resolver._resolve_auth_events( resolved_state[key] = _resolve_auth_events(
events, events,
auth_events auth_events
) )
@ -494,7 +492,7 @@ class Resolver(object):
for key, events in conflicted_state.items(): for key, events in conflicted_state.items():
if key[0] == EventTypes.Member: if key[0] == EventTypes.Member:
logger.debug("Resolving conflicted member lists %r", events) logger.debug("Resolving conflicted member lists %r", events)
resolved_state[key] = Resolver._resolve_auth_events( resolved_state[key] = _resolve_auth_events(
events, events,
auth_events auth_events
) )
@ -504,13 +502,13 @@ class Resolver(object):
for key, events in conflicted_state.items(): for key, events in conflicted_state.items():
if key not in resolved_state: if key not in resolved_state:
logger.debug("Resolving conflicted state %r:%r", key, events) logger.debug("Resolving conflicted state %r:%r", key, events)
resolved_state[key] = Resolver._resolve_normal_events( resolved_state[key] = _resolve_normal_events(
events, auth_events events, auth_events
) )
return resolved_state return resolved_state
@staticmethod
def _resolve_auth_events(events, auth_events): def _resolve_auth_events(events, auth_events):
reverse = [i for i in reversed(_ordered_events(events))] reverse = [i for i in reversed(_ordered_events(events))]
@ -528,7 +526,7 @@ class Resolver(object):
return event return event
@staticmethod
def _resolve_normal_events(events, auth_events): def _resolve_normal_events(events, auth_events):
for event in _ordered_events(events): for event in _ordered_events(events):
try: try: