Put the queue exception at toplevel

This commit is contained in:
mathieui 2019-08-23 21:53:21 +02:00
parent 110bbf8afc
commit a0f5cb6e09
No known key found for this signature in database
GPG Key ID: C59F84CEEFD616E3

View File

@ -34,6 +34,10 @@ from slixmpp.xmlstream.resolver import resolve, default_resolver
RESPONSE_TIMEOUT = 30 RESPONSE_TIMEOUT = 30
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class ContinueQueue(Exception):
"""
Exception raised in the send queue to "continue" from within an inner loop
"""
class NotConnectedError(Exception): class NotConnectedError(Exception):
""" """
@ -896,7 +900,8 @@ class XMLStream(asyncio.BaseProtocol):
""" """
return xml return xml
async def _continue_slow_send(self, async def _continue_slow_send(
self,
task: asyncio.Task, task: asyncio.Task,
already_used: Set[Callable[[ElementBase], Optional[StanzaBase]]] already_used: Set[Callable[[ElementBase], Optional[StanzaBase]]]
) -> None: ) -> None:
@ -934,7 +939,6 @@ class XMLStream(asyncio.BaseProtocol):
""" """
Background loop that processes stanzas to send. Background loop that processes stanzas to send.
""" """
class ContinueQueue(Exception): pass
while True: while True:
(data, use_filters) = await self.waiting_queue.get() (data, use_filters) = await self.waiting_queue.get()
try: try:
@ -961,21 +965,21 @@ class XMLStream(asyncio.BaseProtocol):
else: else:
data = filter(data) data = filter(data)
if data is None: if data is None:
raise Exception('Empty stanza') raise ContinueQueue('Empty stanza')
if isinstance(data, ElementBase): if isinstance(data, ElementBase):
if use_filters: if use_filters:
for filter in self.__filters['out_sync']: for filter in self.__filters['out_sync']:
data = filter(data) data = filter(data)
if data is None: if data is None:
raise Exception('Empty stanza') raise ContinueQueue('Empty stanza')
str_data = tostring(data.xml, xmlns=self.default_ns, str_data = tostring(data.xml, xmlns=self.default_ns,
stream=self, top_level=True) stream=self, top_level=True)
self.send_raw(str_data) self.send_raw(str_data)
else: else:
self.send_raw(data) self.send_raw(data)
except ContinueQueue as exc: except ContinueQueue as exc:
log.info('Stanza in send queue not sent: %s', exc) log.debug('Stanza in send queue not sent: %s', exc)
except Exception: except Exception:
log.error('Exception raised in send queue:', exc_info=True) log.error('Exception raised in send queue:', exc_info=True)
self.waiting_queue.task_done() self.waiting_queue.task_done()