當前位置: 首頁>>代碼示例>>Python>>正文


Python wrappers.Response方法代碼示例

本文整理匯總了Python中flask.wrappers.Response方法的典型用法代碼示例。如果您正苦於以下問題:Python wrappers.Response方法的具體用法?Python wrappers.Response怎麽用?Python wrappers.Response使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在flask.wrappers的用法示例。


在下文中一共展示了wrappers.Response方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: request

# 需要導入模塊: from flask import wrappers [as 別名]
# 或者: from flask.wrappers import Response [as 別名]
def request(self) -> Response:
        return self.client.open(
            method=self.method,
            path=self.path.format(**self.path_parameters),
            json=self.json,
            query_string=self.query_string,
        ) 
開發者ID:JoMingyu,項目名稱:Flask-Large-Application-Example,代碼行數:9,代碼來源:__init__.py

示例2: response

# 需要導入模塊: from flask import wrappers [as 別名]
# 或者: from flask.wrappers import Response [as 別名]
def response(self) -> wrappers.Response:
        return make_response(self.page()) 
開發者ID:PennyDreadfulMTG,項目名稱:Penny-Dreadful-Tools,代碼行數:4,代碼來源:base_view.py

示例3: all_exception_handler

# 需要導入模塊: from flask import wrappers [as 別名]
# 或者: from flask.wrappers import Response [as 別名]
def all_exception_handler(error: Exception) -> Tuple[Response, int]:
    """Catches and handles all exceptions, add more specific error Handlers.
    :param Exception
    :returns Tuple of a Flask Response and int
    """
    return create_response(message=str(error), status=500) 
開發者ID:tko22,項目名稱:flask-boilerplate,代碼行數:8,代碼來源:core.py

示例4: response_factory

# 需要導入模塊: from flask import wrappers [as 別名]
# 或者: from flask.wrappers import Response [as 別名]
def response_factory():
    def create_response(
            data, status_code=200, content_type='application/json'):
        return Response(data, status=status_code, content_type=content_type)
    return create_response 
開發者ID:p1c2u,項目名稱:openapi-core,代碼行數:7,代碼來源:conftest.py

示例5: delete

# 需要導入模塊: from flask import wrappers [as 別名]
# 或者: from flask.wrappers import Response [as 別名]
def delete(self, widgetId: int) -> Response:
        """Delete Single Widget"""
        from flask import jsonify

        id = WidgetService.delete_by_id(widgetId)
        return jsonify(dict(status="Success", id=id)) 
開發者ID:apryor6,項目名稱:flaskerize,代碼行數:8,代碼來源:controller.py

示例6: dispatch_request

# 需要導入模塊: from flask import wrappers [as 別名]
# 或者: from flask.wrappers import Response [as 別名]
def dispatch_request(self, *args, **kwargs):
        """Logic of how to handle a request"""
        method = getattr(self, request.method.lower(), None)
        if method is None and request.method == 'HEAD':
            method = getattr(self, 'get', None)
        assert method is not None, 'Unimplemented method {}'.format(request.method)

        headers = {'Content-Type': 'application/vnd.api+json'}

        response = method(*args, **kwargs)

        if isinstance(response, Response):
            response.headers.add('Content-Type', 'application/vnd.api+json')
            return response

        if not isinstance(response, tuple):
            if isinstance(response, dict):
                response.update({'jsonapi': {'version': '1.0'}})
            return make_response(json.dumps(response, cls=JSONEncoder), 200, headers)

        try:
            data, status_code, headers = response
            headers.update({'Content-Type': 'application/vnd.api+json'})
        except ValueError:
            pass

        try:
            data, status_code = response
        except ValueError:
            pass

        if isinstance(data, dict):
            data.update({'jsonapi': {'version': '1.0'}})

        if isinstance(data, FlaskResponse):
            data.headers.add('Content-Type', 'application/vnd.api+json')
            data.status_code = status_code
            return data
        elif isinstance(data, str):
            json_reponse = data
        else:
            json_reponse = json.dumps(data, cls=JSONEncoder)

        return make_response(json_reponse, status_code, headers) 
開發者ID:miLibris,項目名稱:flask-rest-jsonapi,代碼行數:46,代碼來源:resource.py

示例7: open

# 需要導入模塊: from flask import wrappers [as 別名]
# 或者: from flask.wrappers import Response [as 別名]
def open(self, *args, **kwargs):
        """Modified request.

        Adds token and headers and asserts status code.
        """
        # We are definetly going to add some headers
        if 'headers' not in kwargs:
            kwargs['headers'] = {}

        # Add token
        token = kwargs.pop('token', None)

        if token:
            kwargs['headers'].update({
                # We support a auth header of the form "Token <thetoken>"
                'Authorization': 'Token ' + token
            })

        # Add content-type: json header if nothing else is provided
        if (not("content-type" in kwargs['headers']) and
                ("data" in kwargs)):
            # Parse data
            kwargs['data'] = json.dumps(kwargs['data'])
            # Set header
            kwargs['content_type'] = "application/json"

        # get the actual response and assert status
        expected_code = kwargs.pop('status_code', None)

        response = super().open(*args, **kwargs)

        status_code = response.status_code

        if (expected_code is not None and expected_code != status_code):
            raise AssertionError(
                "Expected a status code of %i, but got %i instead\n"
                "Response:\n%s\n%s\n%s" % (expected_code, status_code,
                                           response, response.data,
                                           response.status))
        elif ((expected_code == 422) and
              ('exception' in response.json.get('_issues', {}))):
            # The validator swallows exceptions and turns them into 'exception'
            # validation errors. Ensure that tests do not miss this by raising
            # them properly.
            error = response.json['_issues']['exception']
            raise AssertionError("Expected a validation error but the "
                                 "validator raised an exception: %s" % error)

        return response 
開發者ID:amiv-eth,項目名稱:amivapi,代碼行數:51,代碼來源:utils.py

示例8: API

# 需要導入模塊: from flask import wrappers [as 別名]
# 或者: from flask.wrappers import Response [as 別名]
def API(method=None):
    if method is None:
        return partial(API)

    @wraps(method)
    def decorated(*args, **kwargs):
        _return = method(*args, **kwargs)

        if isinstance(_return, Response):
            return _return

        if request.url.find('v' + str(API_VERSION)) > 0:
            try:
                if request.headers['Accept'] == API_ACCEPT_HEADER:
                    ret, code = _return
                else:
                    raise KeyError
            except KeyError:
                ret, code = ("Please check request accept again.", status.HTTP_406_NOT_ACCEPTABLE)
        else:
            ret, code = ("API has been updated. The latest version is v" + str(API_VERSION), status.HTTP_301_MOVED_PERMANENTLY)

        return serialize(ret, code)

    def serialize(ret, code):
        _return = {'code': code}

        if not status.is_success(code):
            _return['status'] = 'fail'

            if ret is not None:
                if isinstance(ret, dict):
                    _return.update(ret)
                else:
                    _return['message'] = ret
        else:
            _return['status'] = 'success'

            if ret is not None:
                if isinstance(ret, dict):
                    _return.update(ret)
                else:
                    _return['data'] = ret

        return _return, code

    return decorated 
開發者ID:h4wldev,項目名稱:frest,代碼行數:49,代碼來源:__init__.py


注:本文中的flask.wrappers.Response方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。