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


Python httputil.HTTPMessageDelegate方法代码示例

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


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

示例1: read_stream_body

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import HTTPMessageDelegate [as 别名]
def read_stream_body(stream, callback):
    """Reads an HTTP response from `stream` and runs callback with its
    headers and body."""
    chunks = []

    class Delegate(HTTPMessageDelegate):
        def headers_received(self, start_line, headers):
            self.headers = headers

        def data_received(self, chunk):
            chunks.append(chunk)

        def finish(self):
            callback((self.headers, b''.join(chunks)))
    conn = HTTP1Connection(stream, True)
    conn.read_response(Delegate()) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:18,代码来源:httpserver_test.py

示例2: get_handler_delegate

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import HTTPMessageDelegate [as 别名]
def get_handler_delegate(
        self,
        request: httputil.HTTPServerRequest,
        target_class: Type[RequestHandler],
        target_kwargs: Dict[str, Any] = None,
        path_args: List[bytes] = None,
        path_kwargs: Dict[str, bytes] = None,
    ) -> "_HandlerDelegate":
        """Returns `~.httputil.HTTPMessageDelegate` that can serve a request
        for application and `RequestHandler` subclass.

        :arg httputil.HTTPServerRequest request: current HTTP request.
        :arg RequestHandler target_class: a `RequestHandler` class.
        :arg dict target_kwargs: keyword arguments for ``target_class`` constructor.
        :arg list path_args: positional arguments for ``target_class`` HTTP method that
            will be executed while handling a request (``get``, ``post`` or any other).
        :arg dict path_kwargs: keyword arguments for ``target_class`` HTTP method.
        """
        return _HandlerDelegate(
            self, request, target_class, target_kwargs, path_args, path_kwargs
        ) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:23,代码来源:web.py

示例3: find_handler

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import HTTPMessageDelegate [as 别名]
def find_handler(
        self, request: httputil.HTTPServerRequest, **kwargs: Any
    ) -> Optional[httputil.HTTPMessageDelegate]:
        for rule in self.rules:
            target_params = rule.matcher.match(request)
            if target_params is not None:
                if rule.target_kwargs:
                    target_params["target_kwargs"] = rule.target_kwargs

                delegate = self.get_target_delegate(
                    rule.target, request, **target_params
                )

                if delegate is not None:
                    return delegate

        return None 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:19,代码来源:routing.py

示例4: test_http10_no_content_length

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import HTTPMessageDelegate [as 别名]
def test_http10_no_content_length(self):
        # Regression test for a bug in which can_keep_alive would crash
        # for an HTTP/1.0 (not 1.1) response with no content-length.
        conn = HTTP1Connection(self.client_stream, True)
        self.server_stream.write(b"HTTP/1.0 200 Not Modified\r\n\r\nhello")
        self.server_stream.close()

        event = Event()
        test = self
        body = []

        class Delegate(HTTPMessageDelegate):
            def headers_received(self, start_line, headers):
                test.code = start_line.code

            def data_received(self, data):
                body.append(data)

            def finish(self):
                event.set()

        yield conn.read_response(Delegate())
        yield event.wait()
        self.assertEqual(self.code, 200)
        self.assertEqual(b"".join(body), b"hello") 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:27,代码来源:http1connection_test.py

示例5: get_target_delegate

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import HTTPMessageDelegate [as 别名]
def get_target_delegate(self, target, request, **target_params):
        """Returns an instance of `~.httputil.HTTPMessageDelegate` for a
        Rule's target. This method is called by `~.find_handler` and can be
        extended to provide additional target types.

        :arg target: a Rule's target.
        :arg httputil.HTTPServerRequest request: current request.
        :arg target_params: additional parameters that can be useful
            for `~.httputil.HTTPMessageDelegate` creation.
        """
        if isinstance(target, Router):
            return target.find_handler(request, **target_params)

        elif isinstance(target, httputil.HTTPServerConnectionDelegate):
            return target.start_request(request.server_connection, request.connection)

        elif callable(target):
            return _CallableAdapter(
                partial(target, **target_params), request.connection
            )

        return None 
开发者ID:tp4a,项目名称:teleport,代码行数:24,代码来源:routing.py

示例6: test_http10_no_content_length

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import HTTPMessageDelegate [as 别名]
def test_http10_no_content_length(self):
        # Regression test for a bug in which can_keep_alive would crash
        # for an HTTP/1.0 (not 1.1) response with no content-length.
        conn = HTTP1Connection(self.client_stream, True)
        self.server_stream.write(b"HTTP/1.0 200 Not Modified\r\n\r\nhello")
        self.server_stream.close()

        event = Event()
        test = self
        body = []

        class Delegate(HTTPMessageDelegate):
            def headers_received(self, start_line, headers):
                test.code = start_line.code

            def data_received(self, data):
                body.append(data)

            def finish(self):
                event.set()

        yield conn.read_response(Delegate())
        yield event.wait()
        self.assertEqual(self.code, 200)
        self.assertEqual(b''.join(body), b'hello') 
开发者ID:tp4a,项目名称:teleport,代码行数:27,代码来源:http1connection_test.py

示例7: read_response

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import HTTPMessageDelegate [as 别名]
def read_response(self, delegate):
        """Read a single HTTP response.

        Typical client-mode usage is to write a request using `write_headers`,
        `write`, and `finish`, and then call ``read_response``.

        :arg delegate: a `.HTTPMessageDelegate`

        Returns a `.Future` that resolves to None after the full response has
        been read.
        """
        if self.params.decompress:
            delegate = _GzipMessageDelegate(delegate, self.params.chunk_size)
        return self._read_message(delegate) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:16,代码来源:http1connection.py

示例8: set_close_callback

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import HTTPMessageDelegate [as 别名]
def set_close_callback(self, callback):
        """Sets a callback that will be run when the connection is closed.

        .. deprecated:: 4.0
            Use `.HTTPMessageDelegate.on_connection_close` instead.
        """
        self._close_callback = stack_context.wrap(callback) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:9,代码来源:http1connection.py

示例9: detach

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import HTTPMessageDelegate [as 别名]
def detach(self):
        """Take control of the underlying stream.

        Returns the underlying `.IOStream` object and stops all further
        HTTP processing.  May only be called during
        `.HTTPMessageDelegate.headers_received`.  Intended for implementing
        protocols like websockets that tunnel over an HTTP handshake.
        """
        self._clear_callbacks()
        stream = self.stream
        self.stream = None
        if not self._finish_future.done():
            self._finish_future.set_result(None)
        return stream 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:16,代码来源:http1connection.py

示例10: get_target_delegate

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import HTTPMessageDelegate [as 别名]
def get_target_delegate(
        self, target: Any, request: httputil.HTTPServerRequest, **target_params: Any
    ) -> Optional[httputil.HTTPMessageDelegate]:
        if isclass(target) and issubclass(target, RequestHandler):
            return self.application.get_handler_delegate(
                request, target, **target_params
            )

        return super(_ApplicationRouter, self).get_target_delegate(
            target, request, **target_params
        ) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:13,代码来源:web.py

示例11: start_request

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import HTTPMessageDelegate [as 别名]
def start_request(
        self, server_conn: object, request_conn: httputil.HTTPConnection
    ) -> httputil.HTTPMessageDelegate:
        if isinstance(self.request_callback, httputil.HTTPServerConnectionDelegate):
            delegate = self.request_callback.start_request(server_conn, request_conn)
        else:
            delegate = _CallableAdapter(self.request_callback, request_conn)

        if self.xheaders:
            delegate = _ProxyAdapter(delegate, request_conn)

        return delegate 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:14,代码来源:httpserver.py

示例12: __init__

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import HTTPMessageDelegate [as 别名]
def __init__(
        self,
        delegate: httputil.HTTPMessageDelegate,
        request_conn: httputil.HTTPConnection,
    ) -> None:
        self.connection = request_conn
        self.delegate = delegate 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:9,代码来源:httpserver.py

示例13: __init__

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import HTTPMessageDelegate [as 别名]
def __init__(
        self, router: Router, server_conn: object, request_conn: httputil.HTTPConnection
    ) -> None:
        self.server_conn = server_conn
        self.request_conn = request_conn
        self.delegate = None  # type: Optional[httputil.HTTPMessageDelegate]
        self.router = router  # type: Router 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:9,代码来源:routing.py

示例14: get_target_delegate

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import HTTPMessageDelegate [as 别名]
def get_target_delegate(
        self, target: Any, request: httputil.HTTPServerRequest, **target_params: Any
    ) -> Optional[httputil.HTTPMessageDelegate]:
        """Returns an instance of `~.httputil.HTTPMessageDelegate` for a
        Rule's target. This method is called by `~.find_handler` and can be
        extended to provide additional target types.

        :arg target: a Rule's target.
        :arg httputil.HTTPServerRequest request: current request.
        :arg target_params: additional parameters that can be useful
            for `~.httputil.HTTPMessageDelegate` creation.
        """
        if isinstance(target, Router):
            return target.find_handler(request, **target_params)

        elif isinstance(target, httputil.HTTPServerConnectionDelegate):
            assert request.connection is not None
            return target.start_request(request.server_connection, request.connection)

        elif callable(target):
            assert request.connection is not None
            return _CallableAdapter(
                partial(target, **target_params), request.connection
            )

        return None 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:28,代码来源:routing.py

示例15: read_response

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import HTTPMessageDelegate [as 别名]
def read_response(self, delegate: httputil.HTTPMessageDelegate) -> Awaitable[bool]:
        """Read a single HTTP response.

        Typical client-mode usage is to write a request using `write_headers`,
        `write`, and `finish`, and then call ``read_response``.

        :arg delegate: a `.HTTPMessageDelegate`

        Returns a `.Future` that resolves to a bool after the full response has
        been read. The result is true if the stream is still open.
        """
        if self.params.decompress:
            delegate = _GzipMessageDelegate(delegate, self.params.chunk_size)
        return self._read_message(delegate) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:16,代码来源:http1connection.py


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