From 259dffeb6e4da0b879784ae9642f43c01b95811b Mon Sep 17 00:00:00 2001 From: Tom Nichols Date: Tue, 6 Jul 2010 14:16:46 -0400 Subject: send now has a priority and an 'init' parameter to denote stanzas that may be sent prior to session establishment. --- sleekxmpp/xmlstream/stanzabase.py | 6 +++--- sleekxmpp/xmlstream/xmlstream.py | 13 +++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'sleekxmpp/xmlstream') diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py index 34513807..b9267b88 100644 --- a/sleekxmpp/xmlstream/stanzabase.py +++ b/sleekxmpp/xmlstream/stanzabase.py @@ -383,7 +383,7 @@ class StanzaBase(ElementBase): def exception(self, e): logging.error(traceback.format_tb(e)) - def send(self, priority=False): - if priority: self.stream.sendPriorityRaw(self.__str__()) - else: self.stream.sendRaw(self.__str__()) + def send(self, priority=5, init=False): + self.stream.sendRaw(self.__str__(), priority, init) + diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py index fd0b0fa0..59b0cc62 100644 --- a/sleekxmpp/xmlstream/xmlstream.py +++ b/sleekxmpp/xmlstream/xmlstream.py @@ -219,7 +219,7 @@ class XMLStream(object): while not self.quit.is_set(): if not self.state.ensure('connected',wait=2, block_on_transition=True): continue try: - self.sendPriorityRaw(self.stream_header) + self.sendRaw(self.stream_header, priority=0, init=True) self.__readXML() # this loops until the stream is terminated. except socket.timeout: # TODO currently this will re-send a stream header if this exception occurs. @@ -299,12 +299,9 @@ class XMLStream(object): reconnect = (self.should_reconnect and not self.quit.is_set()) self.disconnect(reconnect=reconnect, error=True) - def sendRaw(self, data): - self.sendqueue.put((1, data)) - return True - - def sendPriorityRaw(self, data): - self.sendqueue.put((0, data)) + def sendRaw( self, data, priority=5, init=False ): + if not self.state.ensure('connected'): return False + self.sendqueue.put((priority, data)) return True def disconnect(self, reconnect=False, error=False): @@ -316,7 +313,7 @@ class XMLStream(object): logging.debug("Disconnecting...") # don't send a footer on error; if the stream is already closed, # this won't get sent until the stream is re-initialized! - if not error: self.sendRaw(self.stream_footer) #send end of stream + if not error: self.sendRaw(self.stream_footer,init=True) #send end of stream try: # self.socket.shutdown(socket.SHUT_RDWR) self.socket.close() -- cgit v1.2.3