diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e99e36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/start.py b/app/start.py new file mode 100644 index 0000000..31ff6e5 --- /dev/null +++ b/app/start.py @@ -0,0 +1,32 @@ +import os +import sys +from http.request import Request +from http.routes import Route +import importlib + + +def app(environ, start_response): + os.environ.setdefault('REQUEST_METHOD', environ['REQUEST_METHOD']) + os.environ.setdefault('URI_PATH', environ['PATH_INFO']) + # print(environ) + router = Route(environ) + # routes = [route.get('/uouo', lambda: 'mario'), route.get('/boo', 'im a ghost')] + + routes = importlib.import_module('views.view').routes + + for route in routes: + print(route.route) + if route.route == router.url: + data = router.get(route.route, route.output) + break + else: + data = 'Route not found' + + data = bytes(data) + # data = bytes(route.get(environ['PATH_INFO'])) + + start_response("200 OK", [ + ("Content-Type", "text/html; charset=utf-8"), + ("Content-Length", str(len(data))) + ]) + return iter([data]) diff --git a/http/__init__.py b/http/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/http/request.py b/http/request.py new file mode 100644 index 0000000..b59ae1d --- /dev/null +++ b/http/request.py @@ -0,0 +1,6 @@ +import os +class Request: + + def __init__(self): + self.method = os.environ['REQUEST_METHOD'] + self.path = os.environ['URI_PATH'] \ No newline at end of file diff --git a/http/routes.py b/http/routes.py new file mode 100644 index 0000000..b7cf0de --- /dev/null +++ b/http/routes.py @@ -0,0 +1,23 @@ +from http.request import Request + +class Route(): + + def __init__(self, environ): + request = Request() + self.url = environ['PATH_INFO'] + + def get(self, route, output): + if (self.url == route): + return output + return None + +class Get(): + + def __init__(self): + pass + + def route(self, route, output): + self.output = output + self.route = route + return self + \ No newline at end of file diff --git a/mine.py b/mine.py new file mode 100644 index 0000000..3b4d8d5 --- /dev/null +++ b/mine.py @@ -0,0 +1,3 @@ +import os +import sys +from app.start import app diff --git a/templates/__init__.py b/templates/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/templates/home.py b/templates/home.py new file mode 100644 index 0000000..a5171bb --- /dev/null +++ b/templates/home.py @@ -0,0 +1,2 @@ +def Home(): + return '

Home Sweet Home

' \ No newline at end of file diff --git a/views/__init__.py b/views/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/views/view.py b/views/view.py new file mode 100644 index 0000000..0758951 --- /dev/null +++ b/views/view.py @@ -0,0 +1,8 @@ +from http.request import Request +from http.routes import Route, Get +from templates.home import Home + +routes = [ + Get().route('/home', Home()), + Get().route('/contact', 'output stuff here too') +]