コード例 #1
0
def create_xrtr_router(uri_data):
    endpoint = Endpoint("xrtr")
    router = RadixTree()
    # static routes
    for u in uri_data.get_static_uris():
        router.insert(u, endpoint, ["GET"])

    # zero variable
    template = uri_data.get_zero_var_uri(ParamFormat.XRTR)
    router.insert(template, endpoint, ["GET"])
    # one variable
    template = uri_data.get_one_var_uri(ParamFormat.XRTR)
    router.insert(template, endpoint, ["GET"])
    # two variables
    template = uri_data.get_two_var_uri(ParamFormat.XRTR)
    router.insert(template, endpoint, ["GET"])
    # three variables
    template = uri_data.get_three_var_uri(ParamFormat.XRTR)
    router.insert(template, endpoint, ["GET"])
    # done
    return router
コード例 #2
0
def create_routes_router(uri_data):
    endpoint = Endpoint("routes")
    router = Mapper()
    # static routes
    for u in uri_data.get_static_uris():
        router.connect(None, u, controller=endpoint)

    # zero variable
    template = uri_data.get_zero_var_uri(ParamFormat.ROUTES)
    router.connect(None, template, controller=endpoint)
    # one variable
    template = uri_data.get_one_var_uri(ParamFormat.ROUTES)
    router.connect(None, template, controller=endpoint)
    # two variables
    template = uri_data.get_two_var_uri(ParamFormat.ROUTES)
    router.connect(None, template, controller=endpoint)
    # three variables
    template = uri_data.get_three_var_uri(ParamFormat.ROUTES)
    router.connect(None, template, controller=endpoint)
    # done
    return router
コード例 #3
0
def create_sanic_router(uri_data):
    endpoint = Endpoint("sanic")
    router = Router()
    # static routes
    for u in uri_data.get_static_uris():
        router.add(u, methods=["GET"], handler=endpoint)

    # zero variable
    template = uri_data.get_zero_var_uri(ParamFormat.SANIC)
    router.add(template, methods=["GET"], handler=endpoint)
    # one variable
    template = uri_data.get_one_var_uri(ParamFormat.SANIC)
    router.add(template, methods=["GET"], handler=endpoint)
    # two variables
    template = uri_data.get_two_var_uri(ParamFormat.SANIC)
    router.add(template, methods=["GET"], handler=endpoint)
    # three variables
    template = uri_data.get_three_var_uri(ParamFormat.SANIC)
    router.add(template, methods=["GET"], handler=endpoint)
    # done
    return router
コード例 #4
0
def create_kua_router(uri_data):
    endpoint = Endpoint("kua")
    router = kua.Routes()
    # static routes
    for u in uri_data.get_static_uris():
        router.add(u, {"GET": endpoint})

    # zero variable
    template = uri_data.get_zero_var_uri(ParamFormat.KUA)
    router.add(template, {"GET": endpoint})
    # one variable
    template = uri_data.get_one_var_uri(ParamFormat.KUA)
    router.add(template, {"GET": endpoint})
    # two variables
    template = uri_data.get_two_var_uri(ParamFormat.KUA)
    router.add(template, {"GET": endpoint})
    # three variables
    template = uri_data.get_three_var_uri(ParamFormat.KUA)
    router.add(template, {"GET": endpoint})
    # done
    return router
コード例 #5
0
def create_hyprtr_router(uri_data):
    endpoint = Endpoint("hyprtr")
    router = HyprtrRouter()

    def format_route(route):
        route = "/" + "/".join([
            part.replace(">", ":int>") if part.isdigit() else part.replace(
                ":*>", ":alpha>")
            for idx, part in enumerate(route.split("/")) if idx > 0
        ])
        print(route)
        return route

    # static routes
    for u in uri_data.get_static_uris():
        router.add(u, methods=["GET"], handler=endpoint)

    # zero variable
    template = uri_data.get_zero_var_uri(ParamFormat.HYPRTR)
    template = format_route(template)
    router.add(template, methods=["GET"], handler=endpoint)
    # one variable
    template = uri_data.get_one_var_uri(ParamFormat.HYPRTR)
    template = format_route(template)
    router.add(template, methods=["GET"], handler=endpoint)
    # two variables
    template = uri_data.get_two_var_uri(ParamFormat.HYPRTR)
    template = format_route(template)
    router.add(template, methods=["GET"], handler=endpoint)
    # three variables
    template = uri_data.get_three_var_uri(ParamFormat.HYPRTR)
    template = format_route(template)
    router.add(template, methods=["GET"], handler=endpoint)

    router.compile()
    # done
    return router