aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/http/semantics.py
diff options
context:
space:
mode:
Diffstat (limited to 'netlib/http/semantics.py')
-rw-r--r--netlib/http/semantics.py46
1 files changed, 39 insertions, 7 deletions
diff --git a/netlib/http/semantics.py b/netlib/http/semantics.py
index 63b6beb9..54bf83d2 100644
--- a/netlib/http/semantics.py
+++ b/netlib/http/semantics.py
@@ -7,6 +7,32 @@ import urlparse
from .. import utils, odict
+CONTENT_MISSING = 0
+
+
+class ProtocolMixin(object):
+
+ def read_request(self):
+ raise NotImplemented
+
+ def read_response(self):
+ raise NotImplemented
+
+ def assemble(self, message):
+ if isinstance(message, Request):
+ return self.assemble_request(message)
+ elif isinstance(message, Response):
+ return self.assemble_response(message)
+ else:
+ raise ValueError("HTTP message not supported.")
+
+ def assemble_request(self, request):
+ raise NotImplemented
+
+ def assemble_response(self, response):
+ raise NotImplemented
+
+
class Request(object):
def __init__(
@@ -18,12 +44,14 @@ class Request(object):
port,
path,
httpversion,
- headers,
- body,
+ headers=None,
+ body=None,
timestamp_start=None,
timestamp_end=None,
):
- assert isinstance(headers, odict.ODictCaseless) or not headers
+ if not headers:
+ headers = odict.ODictCaseless()
+ assert isinstance(headers, odict.ODictCaseless)
self.form_in = form_in
self.method = method
@@ -37,6 +65,7 @@ class Request(object):
self.timestamp_start = timestamp_start
self.timestamp_end = timestamp_end
+
def __eq__(self, other):
try:
self_d = [self.__dict__[k] for k in self.__dict__ if k not in ('timestamp_start', 'timestamp_end')]
@@ -80,14 +109,16 @@ class Response(object):
self,
httpversion,
status_code,
- msg,
- headers,
- body,
+ msg=None,
+ headers=None,
+ body=None,
sslinfo=None,
timestamp_start=None,
timestamp_end=None,
):
- assert isinstance(headers, odict.ODictCaseless) or not headers
+ if not headers:
+ headers = odict.ODictCaseless()
+ assert isinstance(headers, odict.ODictCaseless)
self.httpversion = httpversion
self.status_code = status_code
@@ -98,6 +129,7 @@ class Response(object):
self.timestamp_start = timestamp_start
self.timestamp_end = timestamp_end
+
def __eq__(self, other):
try:
self_d = [self.__dict__[k] for k in self.__dict__ if k not in ('timestamp_start', 'timestamp_end')]