當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。