コード例 #1
0
class IgnoredCustomView(MyAbstractView):
    __ignore__ = True
    app = ObjectProxy()

    @lazy_decorate(app.route("/bar", methods=["GET"]))
    async def company_list(self, request):
        return json({"hello": "ignored"})
コード例 #2
0
class MyCustomView(LazyView):
    app = ObjectProxy()
    sanicjwt = ObjectProxy()

    @lazy_decorate(sanicjwt.protected())
    @lazy_decorate(app.route("/", methods=["GET"]))
    async def company_list(self, request):
        return json({"hello": "world"})

    @lazy_decorate(app.route("/foo", methods=["GET"]),
                   sanicjwt.protected(debug=False))
    async def another_test(self, request):
        print(self.sanicjwt.config.debug())
        return json({"another": "test"})

    @lazy_decorate(app.listener("before_server_start"))
    async def simple_assert_check(self, app, loop):
        assert self.app == app
コード例 #3
0
class MyCustomView(make_lazy_view("MyCustomView", MyViewHelper)):
    app = ObjectProxy()

    @lazy_decorate(app.route("/", methods=["GET"]), app.route("/baz"))
    async def company_list(self, request):
        return json({"hello": "world"})

    @lazy_decorate(app.middleware("response"))
    async def add_sid(self, request, response):
        response.headers.update({"x-sid": self.get_random_string()})
コード例 #4
0
class AnotherCustomView(LazyView):
    app = ObjectProxy()

    @lazy_decorate(app.middleware)
    async def create_request_id(self, request):
        request["request_id"] = uuid.uuid4()

    @lazy_decorate(app.middleware("response"))
    async def attach_request_id(self, request, response):
        response.headers.update(
            {"x-my-custom-uuid": request.get("request_id")})
コード例 #5
0
class SanicSessionView(make_lazy_view("sanic_session")):
    app = ObjectProxy()
    interface = MyInterface()

    @lazy_decorate(app.middleware("request"))
    async def add_session_to_request(self, request):
        await self.interface.open(request)

    @lazy_decorate(app.middleware("response"))
    async def save_session(self, request, response):
        await self.interface.save(request, response)
コード例 #6
0
class MyCustomView(MyAbstractView):
    app = ObjectProxy()

    @lazy_decorate(app.route("/", methods=["GET"]), app.route("/baz"))
    async def company_list(self, request):
        return json({"hello": "world"})

    @lazy_decorate(app.route("/foo", methods=["GET"]))
    @lazy_decorate(app.route("/oof"))
    async def another_test(self, request):
        return json({"another": "test"})

    @lazy_decorate(app.listener("before_server_start"))
    async def simple_assert_check(self, app, loop):
        assert self.app == app
コード例 #7
0
class MyCustomView(make_lazy_view()):
    app = ObjectProxy()

    @lazy_decorate(app.route("/", methods=["GET"]))
    async def company_list(self, request):
        return json({"hello": "world"})