Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Dec 6, 2017
0 parents commit b76790a
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
Empty file added app/__init__.py
Empty file.
32 changes: 32 additions & 0 deletions app/start.py
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 added http/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions http/request.py
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']
23 changes: 23 additions & 0 deletions http/routes.py
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

3 changes: 3 additions & 0 deletions mine.py
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 added templates/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions templates/home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def Home():
return '<h1> Home Sweet Home </h1>'
Empty file added views/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions views/view.py
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')
]

0 comments on commit b76790a

Please sign in to comment.