summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream/xmlstream.py
diff options
context:
space:
mode:
authorTom Nichols <tmnichols@gmail.com>2010-07-01 16:46:37 -0400
committerTom Nichols <tmnichols@gmail.com>2010-07-01 16:46:37 -0400
commitcd2017b8b0641081f3c61b57882b1b3e775beb2e (patch)
treec57bc756ae5b9736eed0e2327b6330a6d61bef49 /sleekxmpp/xmlstream/xmlstream.py
parentdd9f33b7d96c9d69e194d976044be28ce26c34e1 (diff)
downloadslixmpp-cd2017b8b0641081f3c61b57882b1b3e775beb2e.tar.gz
slixmpp-cd2017b8b0641081f3c61b57882b1b3e775beb2e.tar.bz2
slixmpp-cd2017b8b0641081f3c61b57882b1b3e775beb2e.tar.xz
slixmpp-cd2017b8b0641081f3c61b57882b1b3e775beb2e.zip
catch XML parse errors & don't attempt to reconnect. Also removed 'connecting' state from setStream method
Diffstat (limited to 'sleekxmpp/xmlstream/xmlstream.py')
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index 2e7f8724..d5238f80 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -58,8 +58,7 @@ class XMLStream(object):
global ssl_support
self.ssl_support = ssl_support
self.escape_quotes = escape_quotes
- self.state = statemachine.StateMachine(('disconnected','connecting',
- 'connected'))
+ self.state = statemachine.StateMachine(('disconnected','connected'))
self.should_reconnect = True
self.setSocket(socket)
@@ -92,9 +91,11 @@ class XMLStream(object):
def setSocket(self, socket):
"Set the socket"
self.socket = socket
- if socket is not None and self.state.transition('disconnected','connecting'):
- self.filesocket = socket.makefile('rb', 0) # ElementTree.iterparse requires a file. 0 buffer files have to be binary
- self.state.transition('connecting','connected')
+ if socket is not None:
+ with self.state.transition_ctx('disconnected','connected') as locked:
+ if not locked: raise Exception('Already connected')
+ # ElementTree.iterparse requires a file. 0 buffer files have to be binary
+ self.filesocket = socket.makefile('rb', 0)
def setFileSocket(self, filesocket):
self.filesocket = filesocket
@@ -235,6 +236,9 @@ class XMLStream(object):
logging.debug("System interrupt detected")
self.shutdown()
self.eventqueue.put(('quit', None, None))
+ except cElementTree.XMLParserError:
+ logging.warn('XML RCV parsing error!', exc_info=1)
+ # don't restart the stream on an XML parse error.
except:
logging.exception('Unexpected error in RCV thread')
if self.should_reconnect: