Handle methods in standard manner

master
Douglas Blank 2018-07-26 10:03:46 -04:00
rodzic 7bb08a8a22
commit e3afdcd15a
3 zmienionych plików z 12 dodań i 14 usunięć

Wyświetl plik

@ -48,6 +48,7 @@ class DataWrapper():
"""
Wrap a function/method as a route.
"""
methods = ["GET"] if methods is None else methods
def decorator(f):
self._data.routes.append((path, methods, f))
return f
@ -105,6 +106,13 @@ class Manager():
for class_ in ActivityPubBase.CLASSES:
setattr(self, class_, make_wrapper(self, class_))
def run(self):
print("This manager has these filters:")
print(" %s" % [f.__name__ for f in app.get_filters()])
print("This manager has these routes:")
for (route, methods, f) in app.get_routes():
print(" %s %s mapped to %s" % (route, methods, f.__name__))
def render_template(self, template_name, **kwargs):
pass

Wyświetl plik

@ -21,9 +21,6 @@ class FlaskManager(Manager):
def url_for(self, name):
return url_for(name)
def write(self, item):
self._write_data += str(item)
@property
def request(self):
return request
@ -46,7 +43,7 @@ class FlaskManager(Manager):
## Add routes:
for path, methods, f in app._data.routes:
## Add the route:
self.app.route(path)(wrap_function(self, f))
self.app.route(path, methods=methods)(wrap_function(self, f))
## Add filters:
for f in app._data.filters:
## Add the template filter function:

Wyświetl plik

@ -9,19 +9,18 @@ import jinja2
from .base import Manager, wrap_function, app
def make_handler(f, manager):
def make_handler(f, manager, methods):
"""
Make a Tornado Handler
"""
## TODO: handle GET, POST methods
class Handler(RequestHandler):
def get(self):
return f(self)
def render_template(self, name, **kwargs):
self.write(manager.render_template(name, **kwargs))
## redirect is here
return Handler
class TornadoManager(Manager):
@ -63,12 +62,6 @@ class TornadoManager(Manager):
#def login_required():
# tornado.web.authenticated
#def render_template(self, template_name, **kwargs):
# return render_template(template_name, **kwargs)
#def redirect(self, url):
# return redirect(url)
def url_for(self, name):
return url_for(name)
@ -80,7 +73,7 @@ class TornadoManager(Manager):
routes = []
for route, methods, f in app._data.routes:
params = [x.name for x in inspect.signature(f).parameters.values()]
routes.append((route, make_handler(f, self)))
routes.append((route, make_handler(f, self, methods)))
self.app = Application(routes)
self.app.listen(5000)
tornado.ioloop.IOLoop.current().start()