]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
make rdata objects picklable again 487/head
authorPetr Špaček <petr.spacek@nic.cz>
Wed, 27 May 2020 09:06:41 +0000 (11:06 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Wed, 27 May 2020 09:06:41 +0000 (11:06 +0200)
__getstate__ implementation based on tuple and ordered __slots__
is slightly faster than implementation based on dicts.
It also produces smaller blobs.

Speed of this implementation is +- few percents the same
as it was in dnspython 1.16.0 and it now produces smaller blobs.

Fixes: #485
dns/rdata.py

index 6f246c2bd1aded7395ff58131e46efc5e3ce4ac5..b8d65f145ceb7f9f765b6358f1cad0e93577f6e0 100644 (file)
@@ -127,6 +127,13 @@ class Rdata(object):
         # Rdatas are immutable
         raise TypeError("object doesn't support attribute deletion")
 
+    def __getstate__(self):
+        return tuple(getattr(self, slot) for slot in self.__slots__)
+
+    def __setstate__(self, state):
+        for slot, val in zip(self.__slots__, state):
+            object.__setattr__(self, slot, val)
+
     def covers(self):
         """Return the type a Rdata covers.