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


Python Request.application方法代码示例

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


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

示例1: application

# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import application [as 别名]
def application(request):
    file_path = request.path.lstrip(URL_PREFIX) 
    full_path = os.path.join(BASE_PATH, file_path)
    # Protect against path traversal attacks, if they make it this far.
    if not full_path.startswith(BASE_PATH):
        # DANGER!
        return Response("Suspicious url", status=403)
    format = request.args.get('format', None)
    if format == 'raw':
        # Let nginx serve raw files
        accel_path = os.path.join('/accelredir/', file_path)
        return Response('', headers={'X-Accel-Redirect': accel_path})

    try:
        extension = get_extension(full_path, format)
        if extension and extension in handlers:
            return handlers[extension](full_path, format)
        else:
            return Response("No handlers for format %s" % extension, status=400)
    except FileNotFoundError:
        return Response("Not found", status=404)
    return Response(full_path) 
开发者ID:toolforge,项目名称:paws,代码行数:24,代码来源:renderer.py

示例2: respond_with_json

# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import application [as 别名]
def respond_with_json(
            self,
            response_json,
            status: int = 200,
            headers: Optional[Mapping[str, str]] = None,
            content_type: str = "application/json"):
        """
        Registers a respond handler function which responds with a serialized JSON object.

        :param response_json: a JSON-serializable python object
        :param status: the HTTP status of the response
        :param headers: the HTTP headers to be sent (excluding the Content-Type header)
        :param content_type: the content type header to be sent
        """
        response_data = json.dumps(response_json, indent=4)
        self.respond_with_data(response_data, status, headers, content_type=content_type) 
开发者ID:csernazs,项目名称:pytest-httpserver,代码行数:18,代码来源:httpserver.py

示例3: start

# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import application [as 别名]
def start(self):
        """
        Start the server in a thread.

        This method returns immediately (e.g. does not block), and it's the caller's
        responsibility to stop the server (by calling :py:meth:`stop`) when it is no longer needed).

        If the sever is not stopped by the caller and execution reaches the end, the
        program needs to be terminated by Ctrl+C or by signal as it will not terminate until
        the thred is stopped.

        If the sever is already running :py:class:`HTTPServerError` will be raised. If you are
        unsure, call :py:meth:`is_running` first.

        There's a context interface of this class which stops the server when the context block ends.
        """
        if self.is_running():
            raise HTTPServerError("Server is already running")

        self.server = make_server(self.host, self.port, self.application, ssl_context=self.ssl_context)
        self.port = self.server.port  # Update port (needed if `port` was set to 0)
        self.server_thread = threading.Thread(target=self.thread_target)
        self.server_thread.start() 
开发者ID:csernazs,项目名称:pytest-httpserver,代码行数:25,代码来源:httpserver.py

示例4: run_telenium

# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import application [as 别名]
def run_telenium():
    Logger.info("TeleniumClient: Started at 0.0.0.0:9901")
    register_input_provider()

    dispatcher.add_method(rpc_version, "version")
    dispatcher.add_method(rpc_ping, "ping")
    dispatcher.add_method(rpc_get_token, "get_token")
    dispatcher.add_method(rpc_app_quit, "app_quit")
    dispatcher.add_method(rpc_app_ready, "app_ready")
    dispatcher.add_method(rpc_select, "select")
    dispatcher.add_method(rpc_highlight, "highlight")
    dispatcher.add_method(rpc_getattr, "getattr")
    dispatcher.add_method(rpc_setattr, "setattr")
    dispatcher.add_method(rpc_element, "element")
    dispatcher.add_method(rpc_execute, "execute")
    dispatcher.add_method(rpc_pick, "pick")
    dispatcher.add_method(rpc_click_on, "click_on")
    dispatcher.add_method(rpc_drag, "drag")
    dispatcher.add_method(rpc_send_keycode, "send_keycode")

    run_simple("0.0.0.0", 9901, application) 
开发者ID:tito,项目名称:telenium,代码行数:23,代码来源:telenium_client.py

示例5: test_environ_builder_basics

# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import application [as 别名]
def test_environ_builder_basics(self):
        b = EnvironBuilder()
        self.assert_is_none(b.content_type)
        b.method = 'POST'
        self.assert_equal(b.content_type, 'application/x-www-form-urlencoded')
        b.files.add_file('test', BytesIO(b'test contents'), 'test.txt')
        self.assert_equal(b.files['test'].content_type, 'text/plain')
        self.assert_equal(b.content_type, 'multipart/form-data')
        b.form['test'] = 'normal value'

        req = b.get_request()
        b.close()

        self.assert_strict_equal(req.url, u'http://localhost/')
        self.assert_strict_equal(req.method, 'POST')
        self.assert_strict_equal(req.form['test'], u'normal value')
        self.assert_equal(req.files['test'].content_type, 'text/plain')
        self.assert_strict_equal(req.files['test'].filename, u'test.txt')
        self.assert_strict_equal(req.files['test'].read(), b'test contents') 
开发者ID:GeekTrainer,项目名称:Flask,代码行数:21,代码来源:test.py

示例6: test_correct_open_invocation_on_redirect

# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import application [as 别名]
def test_correct_open_invocation_on_redirect(self):
        class MyClient(Client):
            counter = 0
            def open(self, *args, **kwargs):
                self.counter += 1
                env = kwargs.setdefault('environ_overrides', {})
                env['werkzeug._foo'] = self.counter
                return Client.open(self, *args, **kwargs)

        @Request.application
        def test_app(request):
            return Response(str(request.environ['werkzeug._foo']))

        c = MyClient(test_app, response_wrapper=Response)
        self.assert_strict_equal(c.get('/').data, b'1')
        self.assert_strict_equal(c.get('/').data, b'2')
        self.assert_strict_equal(c.get('/').data, b'3') 
开发者ID:GeekTrainer,项目名称:Flask,代码行数:19,代码来源:test.py

示例7: _application

# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import application [as 别名]
def _application(self, request):
        # Add the shutdown method if it is available and has not already
        # been added. This won't be executed via the engine timers.
        shutdown_func = request.environ.get('werkzeug.server.shutdown')
        shutdown_func_name = "shutdown_rpc_server"
        if shutdown_func and shutdown_func_name not in self._dispatcher:
            # Add it to the dispatcher directly.
            self._dispatcher.add_method(shutdown_func, shutdown_func_name)

        # Get a response using the method dispatcher and return it.
        response = JSONRPCResponseManager.handle(
            request.data, self._dispatcher
        )
        return Response(response.json, mimetype='application/json') 
开发者ID:dictation-toolbox,项目名称:dragonfly,代码行数:16,代码来源:server.py

示例8: application

# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import application [as 别名]
def application(request):
    return Response('Hello World!') 
开发者ID:Akagi201,项目名称:learning-python,代码行数:4,代码来源:hello_werkzeug.py

示例9: application

# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import application [as 别名]
def application(self, request: Request):
        """
        Entry point of werkzeug.

        This method is called for each request, and it then calls the undecorated
        :py:meth:`dispatch` method to serve the request.

        :param request: the request object from the werkzeug library
        :return: the response object what the dispatch returned
        """
        request.get_data()
        response = self.dispatch(request)
        self.log.append((request, response))
        return response 
开发者ID:csernazs,项目名称:pytest-httpserver,代码行数:16,代码来源:httpserver.py

示例10: return_reponse

# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import application [as 别名]
def return_reponse(self, data):
        return Response(self.backend._process_response(data),
                        status=http_status_code(data), mimetype='application/json') 
开发者ID:nstack,项目名称:stackhut,代码行数:5,代码来源:backends.py

示例11: application

# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import application [as 别名]
def application(self, request):
        log.debug("Got helper request - {}".format(request.data))
        response = JSONRPCResponseManager.handle(request.data, dispatcher)
        return Response(response.json, mimetype='application/json') 
开发者ID:nstack,项目名称:stackhut,代码行数:6,代码来源:runtime_server.py

示例12: run

# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import application [as 别名]
def run(self):
        # start in a new thread
        log.debug("Starting StackHut helper-server")
        run_simple('localhost', 4000, self.application, threaded=True) 
开发者ID:nstack,项目名称:stackhut,代码行数:6,代码来源:runtime_server.py

示例13: misocoin_app

# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import application [as 别名]
def misocoin_app(request):
    response = JSONRPCResponseManager.handle(request.data, dispatcher)
    return Response(response.json, mimetype='application/json')


# Block management
# Handles the mining of blocks, as well as the automatic adjusting of difficulty 
开发者ID:kendricktan,项目名称:misocoin,代码行数:9,代码来源:misocoind.py

示例14: __init__

# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import application [as 别名]
def __init__(self, alexa, validate_requests=True):
        """
        :param alexa: alexandra.app.App to wrap
        :param validate_requests: Whether or not to do timestamp and
            certificate validation.
        """

        self.alexa = alexa
        self.validate = validate_requests

    # The Request.application decorator handles some boring parts of making
    # this work with WSGI 
开发者ID:erik,项目名称:alexandra,代码行数:14,代码来源:wsgi.py

示例15: wsgi_app

# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import application [as 别名]
def wsgi_app(self, request):
        """Incoming request handler.

        :param request: Werkzeug request object
        """

        try:
            if request.method != 'POST':
                abort(400)

            try:
                # Python 2.7 compatibility
                data = request.data
                if isinstance(data, str):
                    body = json.loads(data)
                else:
                    body = json.loads(data.decode('utf-8'))
            except ValueError:
                abort(400)

            if self.validate:
                valid_cert = util.validate_request_certificate(
                    request.headers, request.data)

                valid_ts = util.validate_request_timestamp(body)

                if not valid_cert or not valid_ts:
                    log.error('failed to validate request')
                    abort(403)

            resp_obj = self.alexa.dispatch_request(body)
            return Response(response=json.dumps(resp_obj, indent=4),
                            status=200,
                            mimetype='application/json')

        except HTTPException as exc:
            log.exception('Failed to handle request')
            return exc 
开发者ID:erik,项目名称:alexandra,代码行数:40,代码来源:wsgi.py


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