mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-24 03:00:15 +00:00
Cleanup logging and exception handling.
The syntax and attribute errors raised during a disconnect/reconnect attempt are now caught and produce nicer log messages.
This commit is contained in:
parent
1735c194cd
commit
8080b4cae2
2 changed files with 36 additions and 30 deletions
|
@ -22,6 +22,8 @@ class FileSocket(_fileobject):
|
|||
|
||||
def read(self, size=4096):
|
||||
"""Read data from the socket as if it were a file."""
|
||||
if self._sock is None:
|
||||
return None
|
||||
data = self._sock.recv(size)
|
||||
if data is not None:
|
||||
return data
|
||||
|
|
|
@ -727,7 +727,7 @@ class XMLStream(object):
|
|||
Defaults to self.auto_reconnect.
|
||||
"""
|
||||
if now:
|
||||
log.debug("SEND: %s" % data)
|
||||
log.debug("SEND (IMMED): %s" % data)
|
||||
try:
|
||||
self.socket.send(data.encode('utf-8'))
|
||||
except Socket.error as serr:
|
||||
|
@ -829,7 +829,9 @@ class XMLStream(object):
|
|||
"""
|
||||
depth = 0
|
||||
root = None
|
||||
for (event, xml) in ET.iterparse(self.filesocket, (b'end', b'start')):
|
||||
try:
|
||||
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.
|
||||
|
@ -858,6 +860,8 @@ class XMLStream(object):
|
|||
# Keep the root element empty of children to
|
||||
# save on memory use.
|
||||
root.clear()
|
||||
except SyntaxError:
|
||||
log.error("Error reading from XML stream.")
|
||||
log.debug("Ending read XML loop")
|
||||
|
||||
def _build_stanza(self, xml, default_ns=None):
|
||||
|
|
Loading…
Reference in a new issue