aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/http/message.py
diff options
context:
space:
mode:
Diffstat (limited to 'netlib/http/message.py')
-rw-r--r--netlib/http/message.py33
1 files changed, 30 insertions, 3 deletions
diff --git a/netlib/http/message.py b/netlib/http/message.py
index 28f55fa2..3d65f93e 100644
--- a/netlib/http/message.py
+++ b/netlib/http/message.py
@@ -4,9 +4,10 @@ import warnings
import six
+from netlib.utils import Serializable
+from .headers import Headers
from .. import encoding, utils
-
CONTENT_MISSING = 0
if six.PY2: # pragma: nocover
@@ -18,7 +19,7 @@ else:
_always_bytes = lambda x: utils.always_bytes(x, "utf-8", "surrogateescape")
-class MessageData(object):
+class MessageData(Serializable):
def __eq__(self, other):
if isinstance(other, MessageData):
return self.__dict__ == other.__dict__
@@ -27,8 +28,24 @@ class MessageData(object):
def __ne__(self, other):
return not self.__eq__(other)
+ def set_state(self, state):
+ for k, v in state.items():
+ if k == "headers":
+ v = Headers.from_state(v)
+ setattr(self, k, v)
+
+ def get_state(self):
+ state = vars(self).copy()
+ state["headers"] = state["headers"].get_state()
+ return state
+
+ @classmethod
+ def from_state(cls, state):
+ state["headers"] = Headers.from_state(state["headers"])
+ return cls(**state)
+
-class Message(object):
+class Message(Serializable):
def __init__(self, data):
self.data = data
@@ -40,6 +57,16 @@ class Message(object):
def __ne__(self, other):
return not self.__eq__(other)
+ def get_state(self):
+ return self.data.get_state()
+
+ def set_state(self, state):
+ self.data.set_state(state)
+
+ @classmethod
+ def from_state(cls, state):
+ return cls(**state)
+
@property
def headers(self):
"""