mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 19:19:54 +00:00
Added a __copy__ method to both ElementBase and StanzaBase.
Stanzas may now be copied using copy.copy(), which will be useful to prevent stanza objects from being shared between event handlers.
This commit is contained in:
parent
253de8518c
commit
9962f1a664
1 changed files with 7 additions and 0 deletions
|
@ -10,6 +10,7 @@ import logging
|
|||
import traceback
|
||||
import sys
|
||||
import weakref
|
||||
import copy
|
||||
|
||||
if sys.version_info < (3,0):
|
||||
from . import tostring26 as tostring
|
||||
|
@ -309,6 +310,9 @@ class ElementBase(tostring.ToString):
|
|||
self.xml.append(xml)
|
||||
return self
|
||||
|
||||
def __copy__(self):
|
||||
return self.__class__(xml=copy.copy(self.xml), parent=self.parent)
|
||||
|
||||
#def __del__(self): #prevents garbage collection of reference cycle
|
||||
# if self.parent is not None:
|
||||
# self.parent.xml.remove(self.xml)
|
||||
|
@ -386,3 +390,6 @@ class StanzaBase(ElementBase):
|
|||
def send(self):
|
||||
self.stream.sendRaw(self.__str__())
|
||||
|
||||
def __copy__(self):
|
||||
return self.__class__(xml=copy.copy(self.xml), stream=self.stream)
|
||||
|
||||
|
|
Loading…
Reference in a new issue