[xmpppy-cvs] non-fatal patch. thanks norman

This commit is contained in:
Nikos Kouremenos 2005-10-11 12:27:27 +00:00
parent c9a368a163
commit ce2b7cad6a
1 changed files with 13 additions and 3 deletions

View File

@ -21,7 +21,7 @@ Contains one tunable attribute: DefaultTimeout (25 seconds by default). It defin
Dispatcher.SendAndWaitForResponce method will wait for reply stanza before giving up. Dispatcher.SendAndWaitForResponce method will wait for reply stanza before giving up.
""" """
import simplexml,time import simplexml,time,sys
from protocol import * from protocol import *
from client import PlugIn from client import PlugIn
@ -37,6 +37,7 @@ class Dispatcher(PlugIn):
self.handlers={} self.handlers={}
self._expected={} self._expected={}
self._defaultHandler=None self._defaultHandler=None
self._pendingExceptions=[]
self._eventHandler=None self._eventHandler=None
self._cycleHandlers=[] self._cycleHandlers=[]
self._exported_methods=[self.Process,self.RegisterHandler,self.RegisterDefaultHandler,\ self._exported_methods=[self.Process,self.RegisterHandler,self.RegisterDefaultHandler,\
@ -114,10 +115,16 @@ class Dispatcher(PlugIn):
2) '0' string if no data were processed but link is alive; 2) '0' string if no data were processed but link is alive;
3) 0 (zero) if underlying connection is closed.""" 3) 0 (zero) if underlying connection is closed."""
for handler in self._cycleHandlers: handler(self) for handler in self._cycleHandlers: handler(self)
if len(self._pendingExceptions) > 0:
_pendingException = self._pendingExceptions.pop()
raise _pendingException[0], _pendingException[1], _pendingException[2]
if self._owner.Connection.pending_data(timeout): if self._owner.Connection.pending_data(timeout):
try: data=self._owner.Connection.receive() try: data=self._owner.Connection.receive()
except IOError: return except IOError: return
self.Stream.Parse(data) self.Stream.Parse(data)
if len(self._pendingExceptions) > 0:
_pendingException = self._pendingExceptions.pop()
raise _pendingException[0], _pendingException[1], _pendingException[2]
return len(data) return len(data)
return '0' # It means that nothing is received but link is alive. return '0' # It means that nothing is received but link is alive.
@ -272,6 +279,7 @@ class Dispatcher(PlugIn):
try: cb(session,stanza,**args) try: cb(session,stanza,**args)
except Exception, typ: except Exception, typ:
if typ.__class__.__name__<>'NodeProcessed': raise if typ.__class__.__name__<>'NodeProcessed': raise
else: else:
session.DEBUG("Expected stanza arrived!",'ok') session.DEBUG("Expected stanza arrived!",'ok')
session._expected[ID]=stanza session._expected[ID]=stanza
@ -281,7 +289,9 @@ class Dispatcher(PlugIn):
try: try:
handler['func'](session,stanza) handler['func'](session,stanza)
except Exception, typ: except Exception, typ:
if typ.__class__.__name__<>'NodeProcessed': raise if typ.__class__.__name__<>'NodeProcessed':
self._pendingExceptions.insert(0, sys.exc_info())
return
user=0 user=0
if user and self._defaultHandler: self._defaultHandler(session,stanza) if user and self._defaultHandler: self._defaultHandler(session,stanza)