コード例 #1
0
        def wrapper(*args, **kwargs):
            resp = f(*args, **kwargs)

            if isinstance(resp, tuple):
                data, code, headers = unpack(resp)
                return self.field.format(data), code, headers
            return self.field.format(resp)
コード例 #2
0
 def wrapper(*args, **kwargs):
     resp = 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)
コード例 #3
0
ファイル: marshalling.py プロジェクト: frol/flask-restplus
        def wrapper(*args, **kwargs):
            resp = f(*args, **kwargs)

            if isinstance(resp, tuple):
                data, code, headers = unpack(resp)
                return self.field.format(data), code, headers
            return self.field.format(resp)
コード例 #4
0
ファイル: marshalling.py プロジェクト: frol/flask-restplus
 def wrapper(*args, **kwargs):
     resp = 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)
コード例 #5
0
 def wrapper(*args, **kwargs):
     resp = f(*args, **kwargs)
     if isinstance(resp, tuple):
         data, code, headers = unpack(resp)
         if code != 200 or data.get('success') is False:
             return resp
         return marshal(data, self.fields, self.envelope), code, headers
     else:
         return marshal(resp, self.fields, self.envelope)
コード例 #6
0
 def wrapper(*args, **kwargs):
     resp = f(*args, **kwargs)
     if isinstance(resp, tuple):
         data, code, headers = unpack(resp)
         if code != 200 or data.get('success') is False:
             return resp
         return marshal(data, self.fields, self.envelope), code, headers
     else:
         return marshal(resp, self.fields, self.envelope)
コード例 #7
0
    def dispatch_request(self, *args, **kwargs):
        """Handle dispatching requests that correspond to custom `APIResource` actions."""

        meth = None

        # Pull the name from the endpoint
        meth = getattr(self, self.action_for_endpoint(request.url_rule.endpoint), None)

        # Custom methods can be defined for `GET` and `POST` requests
        if meth is None:
            if request.method in ('GET', 'POST'):
                # The request action is the last portion of the URL path
                meth = getattr(self, ah.get_request_action(''), None)

        # Below is the implementation from `Resource.dispatch_request`:
        if meth is None:
            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

        for decorator in self.method_decorators:
            meth = decorator(meth)

        resp = meth(*args, **kwargs)

        if isinstance(resp, ResponseBase):  # There may be a better way to test
            return resp

        representations = self.representations or {}

        # noinspection PyUnresolvedReferences
        for mediatype in self.mediatypes():
            if mediatype in representations:
                data, code, headers = unpack(resp)
                resp = representations[mediatype](data, code, headers)
                resp.headers['Content-Type'] = mediatype
                return resp

        return resp
コード例 #8
0
    def dispatch_request(self, *args, **kwargs):

        # Taken from flask
        #noinspection PyUnresolvedReferences
        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

        for decorator in self.method_decorators:
            meth = decorator(meth)

        resp = meth(*args, **kwargs)

        # adds default success key
        if isinstance(resp, dict):
            if resp.get('success', None) is None:
                resp['success'] = True
            elif resp.get('success', True) is False:
                resp = self.__serialize_errors(resp)
        elif isinstance(resp, tuple):
            if resp[0].get('success', True) is False:
                list(resp)[0] = self.__serialize_errors(resp[0])
                resp = tuple(resp)

        if isinstance(resp, ResponseBase):  # There may be a better way to test
            return resp

        representations = self.representations or OrderedDict()

        #noinspection PyUnresolvedReferences
        mediatype = request.accept_mimetypes.best_match(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

        return resp
コード例 #9
0
    def dispatch_request(self, *args, **kwargs):

        # Taken from flask
        #noinspection PyUnresolvedReferences
        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

        for decorator in self.method_decorators:
            meth = decorator(meth)

        resp = meth(*args, **kwargs)

        # adds default success key
        if isinstance(resp, dict):
            if resp.get('success', None) is None:
                resp['success'] = True
            elif resp.get('success', True) is False:
                resp = self.__serialize_errors(resp)
        elif isinstance(resp, tuple):
            if resp[0].get('success', True) is False:
                list(resp)[0] = self.__serialize_errors(resp[0])
                resp = tuple(resp)

        if isinstance(resp, ResponseBase):  # There may be a better way to test
            return resp

        representations = self.representations or OrderedDict()

        #noinspection PyUnresolvedReferences
        mediatype = request.accept_mimetypes.best_match(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

        return resp
コード例 #10
0
ファイル: schema.py プロジェクト: CanalTP/tartare
 def wrapper(*args, **kwargs):
     resp = f(*args, **kwargs)
     if isinstance(resp, tuple):
         data, code, headers = unpack(resp)
         return self.serializer.dump(data), code, headers
     return self.serializer.dump(resp)
コード例 #11
0
ファイル: schema.py プロジェクト: xlqian/tartare
 def wrapper(*args, **kwargs):
     resp = f(*args, **kwargs)
     if isinstance(resp, tuple):
         data, code, headers = unpack(resp)
         return self.serializer.dump(data), code, headers
     return self.serializer.dump(resp)