summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream/xmlstream.py
diff options
context:
space:
mode:
authorThom Nichols <tmnichols@gmail.com>2010-07-01 17:06:50 -0400
committerThom Nichols <tmnichols@gmail.com>2010-07-01 17:06:50 -0400
commitba9633f8f7ef86c73dd02ad316e7963447a6239b (patch)
tree9f4e961fca1fe71a94a443d6e6cb20eafd655d9f /sleekxmpp/xmlstream/xmlstream.py
parent5d87a54913a502b027d4df657a0da1a07a465d7d (diff)
parent065a164223f1cb2df32e438da20b370dc5091578 (diff)
downloadslixmpp-ba9633f8f7ef86c73dd02ad316e7963447a6239b.tar.gz
slixmpp-ba9633f8f7ef86c73dd02ad316e7963447a6239b.tar.bz2
slixmpp-ba9633f8f7ef86c73dd02ad316e7963447a6239b.tar.xz
slixmpp-ba9633f8f7ef86c73dd02ad316e7963447a6239b.zip
Merge branch 'hacks' of github.com:tomstrummer/SleekXMPP into hacks
Diffstat (limited to 'sleekxmpp/xmlstream/xmlstream.py')
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index b669a31d..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:
@@ -352,11 +356,11 @@ class XMLStream(object):
# TODO inefficient linear search; performance might be improved by hashtable lookup
for handler in self.__handlers:
if handler.match(stanza):
- logging.debug('matched stanza to handler %s', handler.name)
+# logging.debug('matched stanza to handler %s', handler.name)
handler.prerun(stanza)
self.eventqueue.put(('stanza', handler, stanza))
if handler.checkDelete():
- logging.debug('deleting callback %s', handler.name)
+# logging.debug('deleting callback %s', handler.name)
self.__handlers.pop(self.__handlers.index(handler))
unhandled = False
if unhandled: