This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
2017-04-11 13:34:09 +01:00
|
|
|
from sanic.response import html
|
2017-04-11 13:46:53 +01:00
|
|
|
from lantern.handle import execute_handle
|
|
|
|
from lantern.error import error_response
|
2017-04-11 14:19:36 +01:00
|
|
|
from lantern.request import serialize_request
|
2017-04-11 13:34:09 +01:00
|
|
|
import os
|
2017-04-11 09:18:20 +01:00
|
|
|
|
|
|
|
|
2017-04-11 21:27:19 +01:00
|
|
|
def build_main_route(args):
|
|
|
|
handle = os.path.abspath(args.handler)
|
|
|
|
if not os.path.isfile(handle) or not os.access(handle, os.X_OK):
|
|
|
|
raise FileNotFoundError("Can't find handle at {}".format(handle))
|
2017-04-11 13:46:53 +01:00
|
|
|
|
2017-04-11 21:27:19 +01:00
|
|
|
async def main_route(request, path=None):
|
|
|
|
result = execute_handle(handle, serialize_request(request))
|
|
|
|
if result.exit_code != 0:
|
|
|
|
return error_response(result.error)
|
|
|
|
|
|
|
|
return html(result.html, status=200)
|
|
|
|
|
|
|
|
return main_route
|