mirror of
https://github.com/ChronosX88/medved.git
synced 2024-11-24 23:42:19 +00:00
28 lines
605 B
Python
28 lines
605 B
Python
import pickle
|
|
|
|
class Message:
|
|
"""Message. Just a pickled dict."""
|
|
def __init__(self, data=None):
|
|
if data is None:
|
|
data = {}
|
|
self._data = data
|
|
|
|
def set(self, key, value):
|
|
self._data[key] = value
|
|
|
|
def get(self, key):
|
|
return self._data.get(key, None)
|
|
|
|
def data(self):
|
|
return self._data
|
|
|
|
def dump(self):
|
|
return pickle.dumps(self)
|
|
|
|
@classmethod
|
|
def load(cls, pickled_data):
|
|
try:
|
|
obj = pickle.loads(pickled_data)
|
|
return cls(obj.data())
|
|
except EOFError:
|
|
return cls({}) |