mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-24 03:00:15 +00:00
Modified xmlstream.py to pass a clean stanza object to each stream handler.
The previous version passed the same stanza object to each registered handler, which can cause issues when the stanza object is modified by one handler. The next handler receives the stanza with the modifications, not the original stanza.
This commit is contained in:
parent
e700a54d11
commit
253de8518c
1 changed files with 7 additions and 7 deletions
|
@ -21,6 +21,7 @@ import threading
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import types
|
import types
|
||||||
|
import copy
|
||||||
import xml.sax.saxutils
|
import xml.sax.saxutils
|
||||||
from . import scheduler
|
from . import scheduler
|
||||||
|
|
||||||
|
@ -305,19 +306,18 @@ class XMLStream(object):
|
||||||
#convert XML into Stanza
|
#convert XML into Stanza
|
||||||
logging.debug("RECV: %s" % cElementTree.tostring(xmlobj))
|
logging.debug("RECV: %s" % cElementTree.tostring(xmlobj))
|
||||||
xmlobj = self.incoming_filter(xmlobj)
|
xmlobj = self.incoming_filter(xmlobj)
|
||||||
stanza = None
|
stanza_type = StanzaBase
|
||||||
for stanza_class in self.__root_stanza:
|
for stanza_class in self.__root_stanza:
|
||||||
if xmlobj.tag == "{%s}%s" % (self.default_ns, stanza_class.name):
|
if xmlobj.tag == "{%s}%s" % (self.default_ns, stanza_class.name):
|
||||||
#if self.__root_stanza[stanza_class].match(xmlobj):
|
stanza_type = stanza_class
|
||||||
stanza = stanza_class(self, xmlobj)
|
|
||||||
break
|
break
|
||||||
if stanza is None:
|
|
||||||
stanza = StanzaBase(self, xmlobj)
|
|
||||||
unhandled = True
|
unhandled = True
|
||||||
|
stanza = stanza_type(self, xmlobj)
|
||||||
for handler in self.__handlers:
|
for handler in self.__handlers:
|
||||||
if handler.match(stanza):
|
if handler.match(stanza):
|
||||||
handler.prerun(stanza)
|
stanza_copy = stanza_type(self, copy.deepcopy(xmlobj))
|
||||||
self.eventqueue.put(('stanza', handler, stanza))
|
handler.prerun(stanza_copy)
|
||||||
|
self.eventqueue.put(('stanza', handler, stanza_copy))
|
||||||
if handler.checkDelete(): self.__handlers.pop(self.__handlers.index(handler))
|
if handler.checkDelete(): self.__handlers.pop(self.__handlers.index(handler))
|
||||||
unhandled = False
|
unhandled = False
|
||||||
if unhandled:
|
if unhandled:
|
||||||
|
|
Loading…
Reference in a new issue