mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 19:19:54 +00:00
Fix regression for handling the case where the server terminates the stream.
The processing loop was continuing to call __read_xml after </stream> was received, which caused SyntaxErrors (can't find starting element). This should fix issue #102
This commit is contained in:
parent
cf7fcf496e
commit
0b83edf439
1 changed files with 35 additions and 35 deletions
|
@ -1084,7 +1084,12 @@ class XMLStream(object):
|
|||
# new connections.
|
||||
if not self.session_started_event.is_set():
|
||||
self.send_raw(self.stream_header, now=True)
|
||||
self.__read_xml()
|
||||
if not self.__read_xml():
|
||||
# If the server terminated the stream, end processing
|
||||
break
|
||||
except SyntaxError as e:
|
||||
log.error("Error reading from XML stream.")
|
||||
self.exception(e)
|
||||
except KeyboardInterrupt:
|
||||
log.debug("Keyboard Escape Detected in _process")
|
||||
self.stop.set()
|
||||
|
@ -1115,9 +1120,7 @@ class XMLStream(object):
|
|||
"""
|
||||
depth = 0
|
||||
root = None
|
||||
try:
|
||||
for (event, xml) in ET.iterparse(self.filesocket,
|
||||
(b'end', b'start')):
|
||||
for event, xml in ET.iterparse(self.filesocket, (b'end', b'start')):
|
||||
if event == b'start':
|
||||
if depth == 0:
|
||||
# We have received the start of the root element.
|
||||
|
@ -1142,13 +1145,10 @@ class XMLStream(object):
|
|||
self.__spawn_event(xml)
|
||||
except RestartStream:
|
||||
return True
|
||||
if root:
|
||||
if root is not None:
|
||||
# Keep the root element empty of children to
|
||||
# save on memory use.
|
||||
root.clear()
|
||||
except SyntaxError:
|
||||
log.error("Error reading from XML stream.")
|
||||
self.disconnect(self.auto_reconnect)
|
||||
log.debug("Ending read XML loop")
|
||||
|
||||
def _build_stanza(self, xml, default_ns=None):
|
||||
|
|
Loading…
Reference in a new issue