From: Petr Špaček Date: Wed, 27 May 2020 09:06:41 +0000 (+0200) Subject: make rdata objects picklable again X-Git-Tag: v2.0.0rc1~151^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4e3eca5c4361f89061e43458034fe0ef6284b62;p=thirdparty%2Fdnspython.git make rdata objects picklable again __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 --- diff --git a/dns/rdata.py b/dns/rdata.py index 6f246c2b..b8d65f14 100644 --- a/dns/rdata.py +++ b/dns/rdata.py @@ -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.