Support transitions >= 0.5.0

transitions 0.5.0 replaced MachineError with ValueError and
AttributeError for exceptions raised when transitioning the state
machine. MachineError is still available in transitions 0.5.0, so we
catch both MachineError and the relevant new exception to work with
both old and new versions of transitions.
pull/8/head
Stein Magnus Jodal 2017-07-26 14:44:39 +02:00
rodzic f433098511
commit d3a6d9d759
3 zmienionych plików z 13 dodań i 10 usunięć

Wyświetl plik

@ -216,9 +216,10 @@ class Broker:
self._retained_messages = dict() self._retained_messages = dict()
self.transitions.start() self.transitions.start()
self.logger.debug("Broker starting") self.logger.debug("Broker starting")
except MachineError as me: except (MachineError, ValueError) as exc:
self.logger.warn("[WARN-0001] Invalid method call at this moment: %s" % me) # Backwards compat: MachineError is raised by transitions < 0.5.0.
raise BrokerException("Broker instance can't be started: %s" % me) self.logger.warning("[WARN-0001] Invalid method call at this moment: %s" % exc)
raise BrokerException("Broker instance can't be started: %s" % exc)
yield from self.plugins_manager.fire_event(EVENT_BROKER_PRE_START) yield from self.plugins_manager.fire_event(EVENT_BROKER_PRE_START)
try: try:
@ -302,9 +303,10 @@ class Broker:
self._subscriptions = dict() self._subscriptions = dict()
self._retained_messages = dict() self._retained_messages = dict()
self.transitions.shutdown() self.transitions.shutdown()
except MachineError as me: except (MachineError, ValueError) as exc:
self.logger.debug("Invalid method call at this moment: %s" % me) # Backwards compat: MachineError is raised by transitions < 0.5.0.
raise BrokerException("Broker instance can't be stopped: %s" % me) self.logger.debug("Invalid method call at this moment: %s" % exc)
raise BrokerException("Broker instance can't be stopped: %s" % exc)
# Fire broker_shutdown event to plugins # Fire broker_shutdown event to plugins
yield from self.plugins_manager.fire_event(EVENT_BROKER_PRE_SHUTDOWN) yield from self.plugins_manager.fire_event(EVENT_BROKER_PRE_SHUTDOWN)
@ -393,7 +395,8 @@ class Broker:
try: try:
client_session.transitions.connect() client_session.transitions.connect()
break break
except MachineError: except (MachineError, ValueError):
# Backwards compat: MachineError is raised by transitions < 0.5.0.
self.logger.warning("Client %s is reconnecting too quickly, make it wait" % client_session.client_id) self.logger.warning("Client %s is reconnecting too quickly, make it wait" % client_session.client_id)
# Wait a bit may be client is reconnecting too fast # Wait a bit may be client is reconnecting too fast
yield from asyncio.sleep(1, loop=self._loop) yield from asyncio.sleep(1, loop=self._loop)

Wyświetl plik

@ -1,5 +1,5 @@
transitions==0.2.5 transitions
websockets==3.3.0 websockets==3.3.0
passlib passlib
docopt docopt
pyyaml pyyaml

Wyświetl plik

@ -17,7 +17,7 @@ setup(
include_package_data=True, include_package_data=True,
platforms='all', platforms='all',
install_requires=[ install_requires=[
'transitions==0.2.5', 'transitions',
'websockets', 'websockets',
'passlib', 'passlib',
'docopt', 'docopt',