diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-02-15 14:58:46 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-02-15 14:58:46 +0100 |
commit | 33fa49277a821b9d38e8c9bf0bcf2adcfa2f6f04 (patch) | |
tree | 31914a601302579ff817504019296fd7e9e46765 /libmproxy/stateobject.py | |
parent | 36f34f701991b5d474c005ec45e3b66e20f326a8 (diff) | |
download | mitmproxy-33fa49277a821b9d38e8c9bf0bcf2adcfa2f6f04.tar.gz mitmproxy-33fa49277a821b9d38e8c9bf0bcf2adcfa2f6f04.tar.bz2 mitmproxy-33fa49277a821b9d38e8c9bf0bcf2adcfa2f6f04.zip |
move mitmproxy
Diffstat (limited to 'libmproxy/stateobject.py')
-rw-r--r-- | libmproxy/stateobject.py | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/libmproxy/stateobject.py b/libmproxy/stateobject.py deleted file mode 100644 index a4a1ffda..00000000 --- a/libmproxy/stateobject.py +++ /dev/null @@ -1,52 +0,0 @@ -from __future__ import absolute_import -from netlib.utils import Serializable - - -class StateObject(Serializable): - - """ - An object with serializable state. - - State attributes can either be serializable types(str, tuple, bool, ...) - or StateObject instances themselves. - """ - - _stateobject_attributes = None - """ - An attribute-name -> class-or-type dict containing all attributes that - should be serialized. If the attribute is a class, it must implement the - Serializable protocol. - """ - - def get_state(self): - """ - Retrieve object state. - """ - state = {} - for attr, cls in self._stateobject_attributes.iteritems(): - val = getattr(self, attr) - if hasattr(val, "get_state"): - state[attr] = val.get_state() - else: - state[attr] = val - return state - - def set_state(self, state): - """ - Load object state from data returned by a get_state call. - """ - state = state.copy() - for attr, cls in self._stateobject_attributes.iteritems(): - if state.get(attr) is None: - setattr(self, attr, state.pop(attr)) - else: - curr = getattr(self, attr) - if hasattr(curr, "set_state"): - curr.set_state(state.pop(attr)) - elif hasattr(cls, "from_state"): - obj = cls.from_state(state.pop(attr)) - setattr(self, attr, obj) - else: # primitive types such as int, str, ... - setattr(self, attr, cls(state.pop(attr))) - if state: - raise RuntimeWarning("Unexpected State in __setstate__: {}".format(state)) |