Created
June 14, 2015 03:44
-
-
Save amjith/43a56b94df5735db9e85 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import wrapt | |
class NotFlask(): | |
def __init__(self): | |
self.routes = {} | |
#def route(self, route_str): | |
#@wrapt.decorator | |
#def decorator(f, instance, args, kwargs): | |
#self.routes[route_str] = f | |
#return f(*args, **kwargs) | |
def route(self, route_str): | |
def decorator(f): | |
self.routes[route_str] = f | |
return f | |
return decorator | |
def serve(self, path): | |
view_function = self.routes.get(path) | |
if view_function: | |
return view_function() | |
else: | |
raise ValueError('Route "{}"" has not been registered'.format(path)) | |
app = NotFlask() | |
@app.route("/") | |
def hello(): | |
return "Hello World!" | |
print app.serve("/") |
GrahamDumpleton
commented
Jun 14, 2015
import wrapt
class NotFlask():
def __init__(self):
self.routes = {}
def route(self, route_str):
@wrapt.decorator
def decorator(f, instance, args, kwargs):
self.routes[route_str] = f
return f
return decorator
#def route(self, route_str):
#def decorator(f):
#self.routes[route_str] = f
#return f
#return decorator
def serve(self, path):
view_function = self.routes.get(path)
if view_function:
return view_function()
else:
raise ValueError('Route "{}"" has not been registered'.format(path))
app = NotFlask()
@app.route("/")
def hello():
return "Hello World!"
class Foo(object):
@app.route('/foo')
def foo(self):
return 'Foo!'
print app.serve("/")
print app.serve("/foo")
[~/t/not_flask]
(wrapt) ↪ python notflask.py
Traceback (most recent call last):
File "notflask.py", line 39, in <module>
print app.serve("/")
File "notflask.py", line 26, in serve
raise ValueError('Route "{}"" has not been registered'.format(path))
ValueError: Route "/"" has not been registered
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment