diff options
-rw-r--r-- | netlib/wsgi.py | 15 | ||||
-rw-r--r-- | test/test_wsgi.py | 24 |
2 files changed, 29 insertions, 10 deletions
diff --git a/netlib/wsgi.py b/netlib/wsgi.py index 0608245c..3c3a8384 100644 --- a/netlib/wsgi.py +++ b/netlib/wsgi.py @@ -1,6 +1,19 @@ import cStringIO, urllib, time, sys, traceback import odict + +class ClientConn: + def __init__(self, address): + self.address = address + + +class Request: + def __init__(self, client_conn, scheme, method, path, headers, content): + self.scheme, self.method, self.path = scheme, method, path + self.headers, self.content = headers, content + self.client_conn = client_conn + + def date_time_string(): """Return the current date and time formatted for a message header.""" WEEKS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] @@ -85,7 +98,7 @@ class WSGIAdaptor: soc.write("HTTP/1.1 %s\r\n"%state["status"]) h = state["headers"] if 'server' not in h: - h["Server"] = [version.NAMEVERSION] + h["Server"] = [self.sversion] if 'date' not in h: h["Date"] = [date_time_string()] soc.write(str(h)) diff --git a/test/test_wsgi.py b/test/test_wsgi.py index c55ab1d8..7763b9e5 100644 --- a/test/test_wsgi.py +++ b/test/test_wsgi.py @@ -1,7 +1,13 @@ import cStringIO, sys import libpry -from netlib import wsgi -import tutils +from netlib import wsgi, odict + + +def treq(): + cc = wsgi.ClientConn(("127.0.0.1", 8888)) + h = odict.ODictCaseless() + h["test"] = ["value"] + return wsgi.Request(cc, "http", "GET", "/", h, "") class TestApp: @@ -16,10 +22,10 @@ class TestApp: return ['Hello', ' world!\n'] -class uWSGIAdaptor(libpry.AutoTree): +class TestWSGI: def test_make_environ(self): - w = wsgi.WSGIAdaptor(None, "foo", 80) - tr = tutils.treq() + w = wsgi.WSGIAdaptor(None, "foo", 80, "version") + tr = treq() assert w.make_environ(tr, None) tr.path = "/foo?bar=voing" @@ -28,8 +34,8 @@ class uWSGIAdaptor(libpry.AutoTree): def test_serve(self): ta = TestApp() - w = wsgi.WSGIAdaptor(ta, "foo", 80) - r = tutils.treq() + w = wsgi.WSGIAdaptor(ta, "foo", 80, "version") + r = treq() r.host = "foo" r.port = 80 @@ -43,8 +49,8 @@ class uWSGIAdaptor(libpry.AutoTree): assert "Server:" in val def _serve(self, app): - w = wsgi.WSGIAdaptor(app, "foo", 80) - r = tutils.treq() + w = wsgi.WSGIAdaptor(app, "foo", 80, "version") + r = treq() r.host = "foo" r.port = 80 wfile = cStringIO.StringIO() |