From a8a7d15805af1887bd26ae35cd952e960fb782d5 Mon Sep 17 00:00:00 2001 From: khamidou Date: Fri, 3 Sep 2010 19:36:18 +0200 Subject: [PATCH 1/1] initial commit --- README | 2 ++ minus.py | 33 +++++++++++++++++++++++++++++++++ testapp.py | 9 +++++++++ 3 files changed, 44 insertions(+) create mode 100644 README create mode 100644 minus.py create mode 100644 testapp.py diff --git a/README b/README new file mode 100644 index 0000000..192ef34 --- /dev/null +++ b/README @@ -0,0 +1,2 @@ +This is minus, a simple wsgi framework. It is not intended to be usable for other purposes +than education. diff --git a/minus.py b/minus.py new file mode 100644 index 0000000..c7edb1c --- /dev/null +++ b/minus.py @@ -0,0 +1,33 @@ +# minus - a microframework in python + +from wsgiref.util import setup_testing_defaults +from wsgiref.simple_server import make_server + +class View(object): + def __init__(self): + self.status = b'200 OK' # By default, everything is always right + self.headers = [(b'Content-type', b'text/plain; charset=utf-8')] + + def do_GET(self): + pass + + def do_POST(self): + pass + +class App(object): + def __init__(self, routings): + self.routings = routings + + def __call__(self, environ, start_response): + if environ["PATH_INFO"] in self.routings: + view = self.routings[environ["PATH_INFO"]]() + + if environ["REQUEST_METHOD"] == "GET": + response = view.do_GET() + start_response(view.status, view.headers) + return response + +def run(app): + httpd = make_server('', 8000, app) + print("Serving on http://localhost:8000") + httpd.serve_forever() diff --git a/testapp.py b/testapp.py new file mode 100644 index 0000000..48baae6 --- /dev/null +++ b/testapp.py @@ -0,0 +1,9 @@ +from minus import * + +class minusApp(View): + def do_GET(self): + return "OH HAI" + +routes = {"/" : minusApp} +app = App(routes) +run(app) -- 2.43.0