Make TLObjects picklable (#752)

This commit is contained in:
vegeta1k95 2018-04-12 19:02:46 +03:00 committed by Lonami
parent bd1b0ecdb4
commit 3bf259d6b3

View File

@ -5,12 +5,35 @@ from threading import Event
class TLObject:
def __init__(self):
self.confirm_received = Event()
self.rpc_error = None
self.result = None
# These should be overrode
self.content_related = False # Only requests/functions/queries are
# Internal parameter to tell pickler in which state Event object was
self._event_is_set = False
self._set_event()
def _set_event(self):
self.confirm_received = Event()
# Set Event state to 'set' if needed
if self._event_is_set:
self.confirm_received.set()
def __getstate__(self):
# Save state of the Event object
self._event_is_set = self.confirm_received.is_set()
# Exclude Event object from dict and return new state
new_dct = dict(self.__dict__)
del new_dct["confirm_received"]
return new_dct
def __setstate__(self, state):
self.__dict__ = state
self._set_event()
# These should not be overrode
@staticmethod