summaryrefslogtreecommitdiff
path: root/sleekxmpp
diff options
context:
space:
mode:
Diffstat (limited to 'sleekxmpp')
-rw-r--r--sleekxmpp/clientxmpp.py3
-rw-r--r--sleekxmpp/plugins/__init__.py5
-rw-r--r--sleekxmpp/plugins/base.py34
-rw-r--r--sleekxmpp/thirdparty/statemachine.py48
4 files changed, 46 insertions, 44 deletions
diff --git a/sleekxmpp/clientxmpp.py b/sleekxmpp/clientxmpp.py
index 57dc2ec0..6a10a52f 100644
--- a/sleekxmpp/clientxmpp.py
+++ b/sleekxmpp/clientxmpp.py
@@ -128,7 +128,8 @@ class ClientXMPP(BaseXMPP):
self.sessionstarted = False
self.bound = False
self.bindfail = False
- self.schedule("session timeout checker", 15, self._session_timeout_check)
+ self.schedule("session timeout checker", 15,
+ self._session_timeout_check)
def _session_timeout_check(self):
if not self.session_started_event.isSet():
diff --git a/sleekxmpp/plugins/__init__.py b/sleekxmpp/plugins/__init__.py
index b51977b8..36fa1771 100644
--- a/sleekxmpp/plugins/__init__.py
+++ b/sleekxmpp/plugins/__init__.py
@@ -2,7 +2,8 @@
SleekXMPP: The Sleek XMPP Library
Copyright (C) 2010 Nathanael C. Fritz
This file is part of SleekXMPP.
-
+
See the file LICENSE for copying permission.
"""
-__all__ = ['xep_0004', 'xep_0030', 'xep_0033', 'xep_0045', 'xep_0050', 'xep_0078', 'xep_0085', 'xep_0092', 'xep_0199', 'gmail_notify', 'xep_0060']
+__all__ = ['xep_0004', 'xep_0030', 'xep_0033', 'xep_0045', 'xep_0050',
+'xep_0078', 'xep_0085', 'xep_0092', 'xep_0199', 'gmail_notify', 'xep_0060']
diff --git a/sleekxmpp/plugins/base.py b/sleekxmpp/plugins/base.py
index a5260b0c..254397e8 100644
--- a/sleekxmpp/plugins/base.py
+++ b/sleekxmpp/plugins/base.py
@@ -2,25 +2,25 @@
SleekXMPP: The Sleek XMPP Library
Copyright (C) 2010 Nathanael C. Fritz
This file is part of SleekXMPP.
-
+
See the file LICENSE for copying permission.
"""
class base_plugin(object):
-
- def __init__(self, xmpp, config):
- self.xep = 'base'
- self.description = 'Base Plugin'
- self.xmpp = xmpp
- self.config = config
- self.post_inited = False
- self.enable = config.get('enable', True)
- if self.enable:
- self.plugin_init()
-
- def plugin_init(self):
- pass
-
- def post_init(self):
- self.post_inited = True
+
+ def __init__(self, xmpp, config):
+ self.xep = 'base'
+ self.description = 'Base Plugin'
+ self.xmpp = xmpp
+ self.config = config
+ self.post_inited = False
+ self.enable = config.get('enable', True)
+ if self.enable:
+ self.plugin_init()
+
+ def plugin_init(self):
+ pass
+
+ def post_init(self):
+ self.post_inited = True
diff --git a/sleekxmpp/thirdparty/statemachine.py b/sleekxmpp/thirdparty/statemachine.py
index 54070db1..b176df02 100644
--- a/sleekxmpp/thirdparty/statemachine.py
+++ b/sleekxmpp/thirdparty/statemachine.py
@@ -17,7 +17,7 @@ class StateMachine(object):
def __init__(self, states=[]):
self.lock = threading.Lock()
self.notifier = threading.Event()
- self.__states= []
+ self.__states = []
self.addStates(states)
self.__default_state = self.__states[0]
self.__current_state = self.__default_state
@@ -28,11 +28,11 @@ class StateMachine(object):
for state in states:
if state in self.__states:
raise IndexError("The state '%s' is already in the StateMachine." % state)
- self.__states.append( state )
+ self.__states.append(state)
finally: self.lock.release()
- def transition(self, from_state, to_state, wait=0.0, func=None, args=[], kwargs={} ):
+ def transition(self, from_state, to_state, wait=0.0, func=None, args=[], kwargs={}):
'''
Transition from the given `from_state` to the given `to_state`.
This method will return `True` if the state machine is now in `to_state`. It
@@ -64,23 +64,23 @@ class StateMachine(object):
`func( *args, **kwargs )`.
'''
- return self.transition_any( (from_state,), to_state, wait=wait,
- func=func, args=args, kwargs=kwargs )
+ return self.transition_any((from_state,), to_state, wait=wait,
+ func=func, args=args, kwargs=kwargs)
- def transition_any(self, from_states, to_state, wait=0.0, func=None, args=[], kwargs={} ):
+ def transition_any(self, from_states, to_state, wait=0.0, func=None, args=[], kwargs={}):
'''
Transition from any of the given `from_states` to the given `to_state`.
'''
if not (isinstance(from_states,tuple) or isinstance(from_states,list)):
- raise ValueError( "from_states should be a list or tuple" )
+ raise ValueError("from_states should be a list or tuple")
for state in from_states:
if not state in self.__states:
- raise ValueError( "StateMachine does not contain from_state %s." % state )
+ raise ValueError("StateMachine does not contain from_state %s." % state)
if not to_state in self.__states:
- raise ValueError( "StateMachine does not contain to_state %s." % to_state )
+ raise ValueError("StateMachine does not contain to_state %s." % to_state)
start = time.time()
while not self.lock.acquire(False):
@@ -110,10 +110,10 @@ class StateMachine(object):
if not return_val: return return_val
log.debug(' ==== TRANSITION %s -> %s', self.__current_state, to_state)
- self._set_state( to_state )
+ self._set_state(to_state)
return return_val # some 'true' value returned by func or True if func was None
else:
- log.error( "StateMachine bug!! The lock should ensure this doesn't happen!" )
+ log.error("StateMachine bug!! The lock should ensure this doesn't happen!")
return False
finally:
self.notifier.set() # notify any waiting threads that the state has changed.
@@ -149,18 +149,18 @@ class StateMachine(object):
'''
if not from_state in self.__states:
- raise ValueError( "StateMachine does not contain from_state %s." % from_state )
+ raise ValueError("StateMachine does not contain from_state %s." % from_state)
if not to_state in self.__states:
- raise ValueError( "StateMachine does not contain to_state %s." % to_state )
+ raise ValueError("StateMachine does not contain to_state %s." % to_state)
return _StateCtx(self, from_state, to_state, wait)
- def ensure(self, state, wait=0.0, block_on_transition=False ):
+ def ensure(self, state, wait=0.0, block_on_transition=False):
'''
Ensure the state machine is currently in `state`, or wait until it enters `state`.
'''
- return self.ensure_any( (state,), wait=wait, block_on_transition=block_on_transition )
+ return self.ensure_any((state,), wait=wait, block_on_transition=block_on_transition)
def ensure_any(self, states, wait=0.0, block_on_transition=False):
@@ -180,7 +180,7 @@ class StateMachine(object):
for state in states:
if not state in self.__states:
- raise ValueError( "StateMachine does not contain state '%s'" % state )
+ raise ValueError("StateMachine does not contain state '%s'" % state)
# if we're in the middle of a transition, determine whether we should
# 'fall back' to the 'current' state, or wait for the new state, in order to
@@ -229,13 +229,13 @@ class StateMachine(object):
return self.__current_state == state
def __str__(self):
- return "".join(( "StateMachine(", ','.join(self.__states), "): ", self.__current_state ))
+ return "".join(("StateMachine(", ','.join(self.__states), "): ", self.__current_state))
class _StateCtx:
- def __init__( self, state_machine, from_state, to_state, wait ):
+ def __init__(self, state_machine, from_state, to_state, wait):
self.state_machine = state_machine
self.from_state = from_state
self.to_state = to_state
@@ -244,30 +244,30 @@ class _StateCtx:
def __enter__(self):
start = time.time()
- while not self.state_machine[ self.from_state ] or not self.state_machine.lock.acquire(False):
+ while not self.state_machine[self.from_state] or not self.state_machine.lock.acquire(False):
# detect timeout:
remainder = start + self.wait - time.time()
if remainder > 0: self.state_machine.notifier.wait(remainder)
else:
- log.debug('StateMachine timeout while waiting for state: %s', self.from_state )
+ log.debug('StateMachine timeout while waiting for state: %s', self.from_state)
return False
self._locked = True # lock has been acquired at this point
self.state_machine.notifier.clear()
log.debug('StateMachine entered context in state: %s',
- self.state_machine.current_state() )
+ self.state_machine.current_state())
return True
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_val is not None:
- log.exception( "StateMachine exception in context, remaining in state: %s\n%s:%s",
- self.state_machine.current_state(), exc_type.__name__, exc_val )
+ log.exception("StateMachine exception in context, remaining in state: %s\n%s:%s",
+ self.state_machine.current_state(), exc_type.__name__, exc_val)
if self._locked:
if exc_val is None:
log.debug(' ==== TRANSITION %s -> %s',
self.state_machine.current_state(), self.to_state)
- self.state_machine._set_state( self.to_state )
+ self.state_machine._set_state(self.to_state)
self.state_machine.notifier.set()
self.state_machine.lock.release()