Пример #1
0
 async def wrapper(request, *args, **kwargs):
     resp = await resource(request, *args, **kwargs)
     if isinstance(resp, BaseHTTPResponse):
         return resp
     else:
         data, code, headers = unpack(resp)
     return self.make_response(request, data, code, headers=headers)
Пример #2
0
    async def dispatch_request(self, request: Request, *args, **kwargs):
        meth = getattr(self, request.method.lower(), None)
        if meth is None and request.method == 'HEAD':
            meth = getattr(self, 'get', None)
        assert meth is not None, 'Unimplemented method %r' % request.method

        if isinstance(self.method_decorators, Mapping):
            decorators = self.method_decorators.get(request.method.lower(), [])
        else:
            decorators = self.method_decorators

        for decorator in decorators:
            meth = decorator(meth)

        resp = await meth(request, *args, **kwargs)
        if isinstance(resp, BaseHTTPResponse):
            return resp

        representations = self.representations or OrderedDict()
        mediatype = accept_mimetypes.best_match(request,
                                                representations,
                                                default=None)
        if mediatype in representations:
            data, code, headers = unpack(resp)
            resp = representations[mediatype](data, code, headers)
            resp.headers['Content-Type'] = mediatype
        return resp
Пример #3
0
 async def wrapper(*args, **kwargs):
     _cls = args[0] if args else None
     if isinstance(_cls, Resource):
         pass
     resp = await f(*args, **kwargs)
     if isinstance(resp, tuple):
         data, code, headers = unpack(resp)
         return marshal(data, self.fields, self.envelope), code, headers
     else:
         return marshal(resp, self.fields, self.envelope)
Пример #4
0
    async def dispatch_request(self, request: Request, *args, **kwargs):
        meth = getattr(self, request.method.lower(), None)

        if self.method_decorators:
            for decorator in self.method_decorators.get(
                    request.method.lower(), []):
                meth = decorator(meth)

        resp = await meth(request, *args, **kwargs)
        if isinstance(resp, BaseHTTPResponse):
            return resp

        representations = self.representations or OrderedDict()
        mediatype = accept_mimetypes.best_match(request,
                                                representations,
                                                default=None)
        if mediatype in representations:
            data, code, headers = unpack(resp)
            resp = representations[mediatype](data, code, headers)
            resp.headers['Content-Type'] = mediatype
        return resp
Пример #5
0
 async def wrapper(*args, **kwargs):
     resp = await f(*args, **kwargs)
     if isinstance(resp, tuple):
         data, code, headers = unpack(resp)
         return self.field.format(data), code, headers
     return self.field.format(resp)