summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream/stanzabase.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-06-06 23:12:54 -0400
committerLance Stout <lancestout@gmail.com>2010-06-06 23:12:54 -0400
commit9962f1a664cfe72b88d78d8541f269f290de8643 (patch)
treed088532add088feb462876e0d72e38f0b9dea7da /sleekxmpp/xmlstream/stanzabase.py
parent253de8518cfb2461f2172fbffd9b2a252924cb00 (diff)
downloadslixmpp-9962f1a664cfe72b88d78d8541f269f290de8643.tar.gz
slixmpp-9962f1a664cfe72b88d78d8541f269f290de8643.tar.bz2
slixmpp-9962f1a664cfe72b88d78d8541f269f290de8643.tar.xz
slixmpp-9962f1a664cfe72b88d78d8541f269f290de8643.zip
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.
Diffstat (limited to 'sleekxmpp/xmlstream/stanzabase.py')
-rw-r--r--sleekxmpp/xmlstream/stanzabase.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py
index 64020c8f..a0d8f5d0 100644
--- a/sleekxmpp/xmlstream/stanzabase.py
+++ b/sleekxmpp/xmlstream/stanzabase.py
@@ -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
@@ -308,6 +309,9 @@ class ElementBase(tostring.ToString):
def appendxml(self, xml):
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:
@@ -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)
+