summaryrefslogtreecommitdiff
path: root/sleekxmpp
diff options
context:
space:
mode:
authorThom Nichols <tmnichols@gmail.com>2010-06-07 14:41:42 -0400
committerThom Nichols <tmnichols@gmail.com>2010-06-07 14:41:42 -0400
commit34dc236126d272a16df0915b010dca0e2e38f0d4 (patch)
treebf856b56b5569de82d2807487130321039b75b4a /sleekxmpp
parent9464736551311c015f1511e7535c762923838eaf (diff)
downloadslixmpp-34dc236126d272a16df0915b010dca0e2e38f0d4.tar.gz
slixmpp-34dc236126d272a16df0915b010dca0e2e38f0d4.tar.bz2
slixmpp-34dc236126d272a16df0915b010dca0e2e38f0d4.tar.xz
slixmpp-34dc236126d272a16df0915b010dca0e2e38f0d4.zip
added documentation for transition_ctx and removed some superfluous comment lines
Diffstat (limited to 'sleekxmpp')
-rw-r--r--sleekxmpp/xmlstream/statemachine.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/sleekxmpp/xmlstream/statemachine.py b/sleekxmpp/xmlstream/statemachine.py
index 704cabdb..c6e0ea41 100644
--- a/sleekxmpp/xmlstream/statemachine.py
+++ b/sleekxmpp/xmlstream/statemachine.py
@@ -105,6 +105,32 @@ class StateMachine(object):
def transition_ctx(self, from_state, to_state, wait=0.0):
+ '''
+ Use the state machine as a context manager. The transition occurs on /exit/ from
+ the `with` context, so long as no exception is thrown. For example:
+
+ ::
+
+ with state_machine.transition_ctx('one','two', wait=5) as locked:
+ if locked:
+ # the state machine is currently locked in state 'one', and will
+ # transition to 'two' when the 'with' statement ends, so long as
+ # no exception is thrown.
+ print 'Currently locked in state one: %s' % state_machine['one']
+
+ else:
+ # The 'wait' timed out, and no lock has been acquired
+ print 'Timed out before entering state "one"'
+
+ print 'Since no exception was thrown, we are now in state "two": %s' % state_machine['two']
+
+
+ The other main difference between this method and `transition()` is that the
+ state machine is locked for the duration of the `with` statement (normally,
+ after a `transition() occurs, the state machine is immediately unlocked and
+ available to another thread to call `transition()` again.
+ '''
+
if not from_state in self.__states:
raise ValueError( "StateMachine does not contain from_state %s." % state )
if not to_state in self.__states: