当前位置: 首页>>代码示例>>Python>>正文


Python wrappers.BaseResponse方法代码示例

本文整理汇总了Python中werkzeug.wrappers.BaseResponse方法的典型用法代码示例。如果您正苦于以下问题:Python wrappers.BaseResponse方法的具体用法?Python wrappers.BaseResponse怎么用?Python wrappers.BaseResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在werkzeug.wrappers的用法示例。


在下文中一共展示了wrappers.BaseResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: application

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import BaseResponse [as 别名]
def application(cls, f):
        """Decorate a function as responder that accepts the request as first
        argument.  This works like the :func:`responder` decorator but the
        function is passed the request object as first argument and the
        request object will be closed automatically::

            @Request.application
            def my_wsgi_app(request):
                return Response('Hello World!')

        :param f: the WSGI callable to decorate
        :return: a new WSGI callable
        """
        #: return a callable that wraps the -2nd argument with the request
        #: and calls the function with all the arguments up to that one and
        #: the request.  The return value is then called with the latest
        #: two arguments.  This makes it possible to use this decorator for
        #: both methods and standalone WSGI functions.
        def application(*args):
            request = cls(args[-2])
            with request:
                return f(*args[:-2] + (request,))(*args[-2:])
        return update_wrapper(application, f) 
开发者ID:jpush,项目名称:jbox,代码行数:25,代码来源:wrappers.py

示例2: test_app

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import BaseResponse [as 别名]
def test_app(environ, start_response):
    """Simple test application that dumps the environment.  You can use
    it to check if Werkzeug is working properly:

    .. sourcecode:: pycon

        >>> from werkzeug.serving import run_simple
        >>> from werkzeug.testapp import test_app
        >>> run_simple('localhost', 3000, test_app)
         * Running on http://localhost:3000/

    The application displays important information from the WSGI environment,
    the Python interpreter and the installed libraries.
    """
    req = Request(environ, populate_request=False)
    if req.args.get('resource') == 'logo':
        response = logo
    else:
        response = Response(render_testapp(req), mimetype='text/html')
    return response(environ, start_response) 
开发者ID:jpush,项目名称:jbox,代码行数:22,代码来源:testapp.py

示例3: _error_handler__

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import BaseResponse [as 别名]
def _error_handler__(cls, fn, e):
        """
        Error handler callback.
        adding _error_handler() or _error_$code()/_error_404(), 
        will trigger this method to return the response
        The method must accept one arg, which is the error object 
        'self' can still be used in your class
        :param fn: the method invoked
        :param e: the error object
        """
        resp = fn(cls, e)
        if isinstance(resp, Response) or isinstance(resp, BaseResponse):
            return resp
        if isinstance(resp, dict) or isinstance(resp, tuple) or resp is None:
            data, status, headers = utils.prepare_view_response(resp)
            # create template from the error name, without the leading _,
            # ie: _error_handler -> error_handler.html, _error_404 -> error_404.html
            # template can be changed using @respone.template('app/class/action.html')
            if "__template__" not in data:
                data["__template__"] = _make_template_path(cls, fn.__name__.lstrip("_"))
            return cls.render(**resp), e.code, headers
        return resp

# ------------------------------------------------------------------------------ 
开发者ID:mardix,项目名称:assembly,代码行数:26,代码来源:assembly.py

示例4: test_flow

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import BaseResponse [as 别名]
def test_flow(self, satosa_config_dict):
        """
        Performs the test.
        """
        test_client = Client(make_app(SATOSAConfig(satosa_config_dict)), BaseResponse)

        # Make request to frontend
        resp = test_client.get('/{}/{}/request'.format("backend", "frontend"))
        assert resp.status == '200 OK'
        headers = dict(resp.headers)
        assert headers["Set-Cookie"]

        # Fake response coming in to backend
        resp = test_client.get('/{}/response'.format("backend"), headers=[("Cookie", headers["Set-Cookie"])])
        assert resp.status == '200 OK'
        assert resp.data.decode('utf-8') == "Auth response received, passed to test frontend" 
开发者ID:IdentityPython,项目名称:SATOSA,代码行数:18,代码来源:test_wsgi_flow.py

示例5: test_full_path

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import BaseResponse [as 别名]
def test_full_path(self):
        trace_id = trace_sdk.generate_trace_id()
        # We need to use the Werkzeug test app because
        # The headers are injected at the wsgi layer.
        # The flask test app will not include these, and
        # result in the values not propagated.
        client = Client(self.app.wsgi_app, BaseResponse)
        # emulate b3 headers
        client.get(
            "/",
            headers={
                "traceparent": "00-{:032x}-{:016x}-{:02x}".format(
                    trace_id,
                    trace_sdk.generate_span_id(),
                    trace.TraceFlags.SAMPLED,
                )
            },
        )
        # assert the http request header was propagated through.
        prepared_request = self.send.call_args[0][1]
        headers = prepared_request.headers
        self.assertRegex(
            headers["traceparent"],
            r"00-{:032x}-[0-9a-f]{{16}}-01".format(trace_id),
        ) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:27,代码来源:test_flask_example.py

示例6: test_uninstrument

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import BaseResponse [as 别名]
def test_uninstrument(self):
        # pylint: disable=access-member-before-definition
        resp = self.client.get("/hello/123")
        self.assertEqual(200, resp.status_code)
        self.assertEqual([b"Hello: 123"], list(resp.response))
        span_list = self.memory_exporter.get_finished_spans()
        self.assertEqual(len(span_list), 1)

        FlaskInstrumentor().uninstrument()
        self.app = flask.Flask(__name__)

        self.app.route("/hello/<int:helloid>")(self._hello_endpoint)
        # pylint: disable=attribute-defined-outside-init
        self.client = Client(self.app, BaseResponse)

        resp = self.client.get("/hello/123")
        self.assertEqual(200, resp.status_code)
        self.assertEqual([b"Hello: 123"], list(resp.response))
        span_list = self.memory_exporter.get_finished_spans()
        self.assertEqual(len(span_list), 1) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:22,代码来源:test_automatic.py

示例7: _common_initialization

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import BaseResponse [as 别名]
def _common_initialization(self, config):
        # pylint: disable=unused-argument
        def excluded_endpoint(request):
            return Response("excluded")

        # pylint: disable=unused-argument
        def excluded2_endpoint(request):
            return Response("excluded2")

        config.add_route("hello", "/hello/{helloid}")
        config.add_view(self._hello_endpoint, route_name="hello")
        config.add_route("excluded_arg", "/excluded/{helloid}")
        config.add_view(self._hello_endpoint, route_name="excluded_arg")
        config.add_route("excluded", "/excluded_noarg")
        config.add_view(excluded_endpoint, route_name="excluded")
        config.add_route("excluded2", "/excluded_noarg2")
        config.add_view(excluded2_endpoint, route_name="excluded2")

        # pylint: disable=attribute-defined-outside-init
        self.client = Client(config.make_wsgi_app(), BaseResponse) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:22,代码来源:pyramid_base_test.py

示例8: _warn_if_string

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import BaseResponse [as 别名]
def _warn_if_string(iterable):
    """Helper for the response objects to check if the iterable returned
    to the WSGI server is not a string.
    """
    if isinstance(iterable, string_types):
        warnings.warn(
            "Response iterable was set to a string. This will appear to"
            " work but means that the server will send the data to the"
            " client one character at a time. This is almost never"
            " intended behavior, use 'response.data' to assign strings"
            " to the response object.",
            stacklevel=2,
        ) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:base_response.py

示例9: execute_command

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import BaseResponse [as 别名]
def execute_command(self, request, command, frame):
        """Execute a command in a console."""
        return Response(frame.console.eval(command), mimetype='text/html') 
开发者ID:jpush,项目名称:jbox,代码行数:5,代码来源:__init__.py

示例10: display_console

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import BaseResponse [as 别名]
def display_console(self, request):
        """Display a standalone shell."""
        if 0 not in self.frames:
            if self.console_init_func is None:
                ns = {}
            else:
                ns = dict(self.console_init_func())
            ns.setdefault('app', self.app)
            self.frames[0] = _ConsoleFrame(ns)
        is_trusted = bool(self.check_pin_trust(request.environ))
        return Response(render_console_html(secret=self.secret,
                                            evalex_trusted=is_trusted),
                        mimetype='text/html') 
开发者ID:jpush,项目名称:jbox,代码行数:15,代码来源:__init__.py

示例11: paste_traceback

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import BaseResponse [as 别名]
def paste_traceback(self, request, traceback):
        """Paste the traceback and return a JSON response."""
        rv = traceback.paste()
        return Response(json.dumps(rv), mimetype='application/json') 
开发者ID:jpush,项目名称:jbox,代码行数:6,代码来源:__init__.py

示例12: get_resource

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import BaseResponse [as 别名]
def get_resource(self, request, filename):
        """Return a static resource from the shared folder."""
        filename = join(dirname(__file__), 'shared', basename(filename))
        if isfile(filename):
            mimetype = mimetypes.guess_type(filename)[0] \
                or 'application/octet-stream'
            f = open(filename, 'rb')
            try:
                return Response(f.read(), mimetype=mimetype)
            finally:
                f.close()
        return Response('Not Found', status=404) 
开发者ID:jpush,项目名称:jbox,代码行数:14,代码来源:__init__.py

示例13: get_response

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import BaseResponse [as 别名]
def get_response(self):
        """Return a response object for the feed."""
        return BaseResponse(self.to_string(), mimetype='application/atom+xml') 
开发者ID:jpush,项目名称:jbox,代码行数:5,代码来源:atom.py

示例14: application

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import BaseResponse [as 别名]
def application(cls, f):
        """Decorate a function as responder that accepts the request as first
        argument.  This works like the :func:`responder` decorator but the
        function is passed the request object as first argument and the
        request object will be closed automatically::

            @Request.application
            def my_wsgi_app(request):
                return Response('Hello World!')

        As of Werkzeug 0.14 HTTP exceptions are automatically caught and
        converted to responses instead of failing.

        :param f: the WSGI callable to decorate
        :return: a new WSGI callable
        """
        #: return a callable that wraps the -2nd argument with the request
        #: and calls the function with all the arguments up to that one and
        #: the request.  The return value is then called with the latest
        #: two arguments.  This makes it possible to use this decorator for
        #: both methods and standalone WSGI functions.
        from werkzeug.exceptions import HTTPException

        def application(*args):
            request = cls(args[-2])
            with request:
                try:
                    resp = f(*args[:-2] + (request,))
                except HTTPException as e:
                    resp = e.get_response(args[-2])
                return resp(*args[-2:])

        return update_wrapper(application, f) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:35,代码来源:wrappers.py

示例15: _wrap_response

# 需要导入模块: from werkzeug import wrappers [as 别名]
# 或者: from werkzeug.wrappers import BaseResponse [as 别名]
def _wrap_response(self, start, length):
        """Wrap existing Response in case of Range Request context."""
        if self.status_code == 206:
            self.response = _RangeWrapper(self.response, start, length) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:6,代码来源:wrappers.py


注:本文中的werkzeug.wrappers.BaseResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。