-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b76790a
Showing
11 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import os | ||
class Request: | ||
|
||
def __init__(self): | ||
self.method = os.environ['REQUEST_METHOD'] | ||
self.path = os.environ['URI_PATH'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import os | ||
import sys | ||
from app.start import app |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def Home(): | ||
return '<h1> Home Sweet Home </h1>' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
] |