diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-05-31 17:16:31 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-05-31 17:16:31 +1200 |
commit | 08fbe6f1118455bc44d05db30b83bdf81feda2a0 (patch) | |
tree | 38db5d8f3e1e52e09a9348d15db368ae3baa9b86 /netlib/basetypes.py | |
parent | 2f526393d29b6a03e43d1f6240175b4dfb13dc7d (diff) | |
download | mitmproxy-08fbe6f1118455bc44d05db30b83bdf81feda2a0.tar.gz mitmproxy-08fbe6f1118455bc44d05db30b83bdf81feda2a0.tar.bz2 mitmproxy-08fbe6f1118455bc44d05db30b83bdf81feda2a0.zip |
Start cleaning up netlib.utils
- Remove http2 functions, move to http2.frame
- Remove Serializable, move to netlib.basetypes
Diffstat (limited to 'netlib/basetypes.py')
-rw-r--r-- | netlib/basetypes.py | 33 |
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()) |