fritzy / SleekXMPP

Python 2.6+/3.1+ XMPP Library
http://groups.google.com/group/sleekxmpp-discussion
Other
1.1k stars 299 forks source link

JID's are not __deepcopy__ able. #262

Closed jbzdak closed 11 years ago

jbzdak commented 11 years ago

When I tried deepcopying object containing a JID following error occoured.

In [1]: from sleekxmpp.jid import JID
In [2]: from copy import deepcopy 
In [3]: deepcopy(JID())
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-89cd7190e165> in <module>()
----> 1 deepcopy(JID())

/home/jb/.virtualenvs/silf-backend-commons/lib/python3.3/copy.py in deepcopy(x, memo, _nil)
    164                     reductor = getattr(x, "__reduce_ex__", None)
    165                     if reductor:
--> 166                         rv = reductor(2)
    167                     else:
    168                         reductor = getattr(x, "__reduce__", None)

TypeError: 'NoneType' object is not callable

I have no idea whatsoever what is wrong, but following diff fixes this error:

Index: sleekxmpp/jid.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- sleekxmpp/jid.py    (date 1361556515000)
+++ sleekxmpp/jid.py    (date 1380039393000)
@@ -21,6 +21,7 @@

 from sleekxmpp.util import stringprep_profiles
 from sleekxmpp.thirdparty import OrderedDict
+from copy import deepcopy

 #: These characters are not allowed to appear in a JID.
 ILLEGAL_CHARS = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r' + \
@@ -580,3 +581,8 @@
     def __copy__(self):
         """Generate a duplicate JID."""
         return JID(self)
+
+    def __deepcopy__(self, memo):
+        """Generate a duplicate JID."""
+        return JID(deepcopy(str(self), memo))
+
legastero commented 11 years ago

Fixed in develop branch.

Thanks for the diff!