mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 19:19:54 +00:00
Fix RESPONSE_TIMEOUT dependency loops.
This commit is contained in:
parent
b8114b25ed
commit
6ee8a2980c
3 changed files with 20 additions and 8 deletions
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
from sleekxmpp.stanza import Error
|
from sleekxmpp.stanza import Error
|
||||||
from sleekxmpp.stanza.rootstanza import RootStanza
|
from sleekxmpp.stanza.rootstanza import RootStanza
|
||||||
from sleekxmpp.xmlstream import RESPONSE_TIMEOUT, StanzaBase, ET
|
from sleekxmpp.xmlstream import StanzaBase, ET
|
||||||
from sleekxmpp.xmlstream.handler import Waiter
|
from sleekxmpp.xmlstream.handler import Waiter
|
||||||
from sleekxmpp.xmlstream.matcher import MatcherId
|
from sleekxmpp.xmlstream.matcher import MatcherId
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ class Iq(RootStanza):
|
||||||
StanzaBase.reply(self)
|
StanzaBase.reply(self)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def send(self, block=True, timeout=RESPONSE_TIMEOUT):
|
def send(self, block=True, timeout=None):
|
||||||
"""
|
"""
|
||||||
Send an <iq> stanza over the XML stream.
|
Send an <iq> stanza over the XML stream.
|
||||||
|
|
||||||
|
@ -174,6 +174,8 @@ class Iq(RootStanza):
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
"""
|
"""
|
||||||
|
if timeout is None:
|
||||||
|
timeout = self.stream.response_timeout
|
||||||
if block and self['type'] in ('get', 'set'):
|
if block and self['type'] in ('get', 'set'):
|
||||||
waitfor = Waiter('IqWait_%s' % self['id'], MatcherId(self['id']))
|
waitfor = Waiter('IqWait_%s' % self['id'], MatcherId(self['id']))
|
||||||
self.stream.registerHandler(waitfor)
|
self.stream.registerHandler(waitfor)
|
||||||
|
|
|
@ -12,7 +12,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import Queue as queue
|
import Queue as queue
|
||||||
|
|
||||||
from sleekxmpp.xmlstream import StanzaBase, RESPONSE_TIMEOUT
|
from sleekxmpp.xmlstream import StanzaBase
|
||||||
from sleekxmpp.xmlstream.handler.base import BaseHandler
|
from sleekxmpp.xmlstream.handler.base import BaseHandler
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ class Waiter(BaseHandler):
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def wait(self, timeout=RESPONSE_TIMEOUT):
|
def wait(self, timeout=None):
|
||||||
"""
|
"""
|
||||||
Block an event handler while waiting for a stanza to arrive.
|
Block an event handler while waiting for a stanza to arrive.
|
||||||
|
|
||||||
|
@ -84,6 +84,9 @@ class Waiter(BaseHandler):
|
||||||
arrive. Defaults to the global default timeout
|
arrive. Defaults to the global default timeout
|
||||||
value sleekxmpp.xmlstream.RESPONSE_TIMEOUT.
|
value sleekxmpp.xmlstream.RESPONSE_TIMEOUT.
|
||||||
"""
|
"""
|
||||||
|
if timeout is None:
|
||||||
|
timeout = self.stream.response_timeout
|
||||||
|
|
||||||
try:
|
try:
|
||||||
stanza = self._payload.get(True, timeout)
|
stanza = self._payload.get(True, timeout)
|
||||||
except queue.Empty:
|
except queue.Empty:
|
||||||
|
|
|
@ -25,6 +25,8 @@ except ImportError:
|
||||||
from sleekxmpp.thirdparty.statemachine import StateMachine
|
from sleekxmpp.thirdparty.statemachine import StateMachine
|
||||||
from sleekxmpp.xmlstream import Scheduler, tostring
|
from sleekxmpp.xmlstream import Scheduler, tostring
|
||||||
from sleekxmpp.xmlstream.stanzabase import StanzaBase, ET
|
from sleekxmpp.xmlstream.stanzabase import StanzaBase, ET
|
||||||
|
from sleekxmpp.xmlstream.handler import Waiter, XMLCallback
|
||||||
|
from sleekxmpp.xmlstream.matcher import MatchXMLMask
|
||||||
|
|
||||||
# In Python 2.x, file socket objects are broken. A patched socket
|
# In Python 2.x, file socket objects are broken. A patched socket
|
||||||
# wrapper is provided for this case in filesocket.py.
|
# wrapper is provided for this case in filesocket.py.
|
||||||
|
@ -162,6 +164,8 @@ class XMLStream(object):
|
||||||
self.ssl_support = SSL_SUPPORT
|
self.ssl_support = SSL_SUPPORT
|
||||||
self.ssl_version = ssl.PROTOCOL_TLSv1
|
self.ssl_version = ssl.PROTOCOL_TLSv1
|
||||||
|
|
||||||
|
self.response_timeout = RESPONSE_TIMEOUT
|
||||||
|
|
||||||
self.state = StateMachine(('disconnected', 'connected'))
|
self.state = StateMachine(('disconnected', 'connected'))
|
||||||
self.state._set_state('disconnected')
|
self.state._set_state('disconnected')
|
||||||
|
|
||||||
|
@ -458,8 +462,6 @@ class XMLStream(object):
|
||||||
"""
|
"""
|
||||||
# To prevent circular dependencies, we must load the matcher
|
# To prevent circular dependencies, we must load the matcher
|
||||||
# and handler classes here.
|
# and handler classes here.
|
||||||
from sleekxmpp.xmlstream.matcher import MatchXMLMask
|
|
||||||
from sleekxmpp.xmlstream.handler import XMLCallback
|
|
||||||
|
|
||||||
if name is None:
|
if name is None:
|
||||||
name = 'add_handler_%s' % self.getNewId()
|
name = 'add_handler_%s' % self.getNewId()
|
||||||
|
@ -606,7 +608,7 @@ class XMLStream(object):
|
||||||
"""
|
"""
|
||||||
return xml
|
return xml
|
||||||
|
|
||||||
def send(self, data, mask=None, timeout=RESPONSE_TIMEOUT):
|
def send(self, data, mask=None, timeout=None):
|
||||||
"""
|
"""
|
||||||
A wrapper for send_raw for sending stanza objects.
|
A wrapper for send_raw for sending stanza objects.
|
||||||
|
|
||||||
|
@ -621,6 +623,9 @@ class XMLStream(object):
|
||||||
timeout -- Time in seconds to wait for a response before
|
timeout -- Time in seconds to wait for a response before
|
||||||
continuing. Defaults to RESPONSE_TIMEOUT.
|
continuing. Defaults to RESPONSE_TIMEOUT.
|
||||||
"""
|
"""
|
||||||
|
if timeout is None:
|
||||||
|
timeout = self.response_timeout
|
||||||
|
|
||||||
if hasattr(mask, 'xml'):
|
if hasattr(mask, 'xml'):
|
||||||
mask = mask.xml
|
mask = mask.xml
|
||||||
data = str(data)
|
data = str(data)
|
||||||
|
@ -643,7 +648,7 @@ class XMLStream(object):
|
||||||
self.send_queue.put(data)
|
self.send_queue.put(data)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def send_xml(self, data, mask=None, timeout=RESPONSE_TIMEOUT):
|
def send_xml(self, data, mask=None, timeout=None):
|
||||||
"""
|
"""
|
||||||
Send an XML object on the stream, and optionally wait
|
Send an XML object on the stream, and optionally wait
|
||||||
for a response.
|
for a response.
|
||||||
|
@ -657,6 +662,8 @@ class XMLStream(object):
|
||||||
timeout -- Time in seconds to wait for a response before
|
timeout -- Time in seconds to wait for a response before
|
||||||
continuing. Defaults to RESPONSE_TIMEOUT.
|
continuing. Defaults to RESPONSE_TIMEOUT.
|
||||||
"""
|
"""
|
||||||
|
if timeout is None:
|
||||||
|
timeout = self.response_timeout
|
||||||
return self.send(tostring(data), mask, timeout)
|
return self.send(tostring(data), mask, timeout)
|
||||||
|
|
||||||
def process(self, threaded=True):
|
def process(self, threaded=True):
|
||||||
|
|
Loading…
Reference in a new issue