aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/basetypes.py
diff options
context:
space:
mode:
Diffstat (limited to 'netlib/basetypes.py')
-rw-r--r--netlib/basetypes.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/netlib/basetypes.py b/netlib/basetypes.py
new file mode 100644
index 00000000..d03246ff
--- /dev/null
+++ b/netlib/basetypes.py
@@ -0,0 +1,33 @@
+import six
+import abc
+
+@six.add_metaclass(abc.ABCMeta)
+class Serializable(object):
+ """
+ Abstract Base Class that defines an API to save an object's state and restore it later on.
+ """
+
+ @classmethod
+ @abc.abstractmethod
+ def from_state(cls, state):
+ """
+ Create a new object from the given state.
+ """
+ raise NotImplementedError()
+
+ @abc.abstractmethod
+ def get_state(self):
+ """
+ Retrieve object state.
+ """
+ raise NotImplementedError()
+
+ @abc.abstractmethod
+ def set_state(self, state):
+ """
+ Set object state to the given state.
+ """
+ raise NotImplementedError()
+
+ def copy(self):
+ return self.from_state(self.get_state())