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


Python simple_httpclient.SimpleAsyncHTTPClient方法代码示例

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


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

示例1: main

# 需要导入模块: from tornado import simple_httpclient [as 别名]
# 或者: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
def main():
    parse_command_line()
    app = Application([('/', ChunkHandler)])
    app.listen(options.port, address='127.0.0.1')

    def callback(response):
        response.rethrow()
        assert len(response.body) == (options.num_chunks * options.chunk_size)
        logging.warning("fetch completed in %s seconds", response.request_time)
        IOLoop.current().stop()

    logging.warning("Starting fetch with curl client")
    curl_client = CurlAsyncHTTPClient()
    curl_client.fetch('http://localhost:%d/' % options.port,
                      callback=callback)
    IOLoop.current().start()

    logging.warning("Starting fetch with simple client")
    simple_client = SimpleAsyncHTTPClient()
    simple_client.fetch('http://localhost:%d/' % options.port,
                        callback=callback)
    IOLoop.current().start() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:24,代码来源:chunk_benchmark.py

示例2: __new__

# 需要导入模块: from tornado import simple_httpclient [as 别名]
# 或者: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
def __new__(cls, io_loop=None, force_instance=False, **kwargs):
        io_loop = io_loop or IOLoop.current()
        if force_instance:
            instance_cache = None
        else:
            instance_cache = cls._async_clients()
        if instance_cache is not None and io_loop in instance_cache:
            return instance_cache[io_loop]
        instance = super(AsyncHTTPClient, cls).__new__(cls, io_loop=io_loop,
                                                       **kwargs)
        # Make sure the instance knows which cache to remove itself from.
        # It can't simply call _async_clients() because we may be in
        # __new__(AsyncHTTPClient) but instance.__class__ may be
        # SimpleAsyncHTTPClient.
        instance._instance_cache = instance_cache
        if instance_cache is not None:
            instance_cache[instance.io_loop] = instance
        return instance 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:20,代码来源:httpclient.py

示例3: configure

# 需要导入模块: from tornado import simple_httpclient [as 别名]
# 或者: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
def configure(cls, impl, **kwargs):
        """配置要使用的 `AsyncHTTPClient` 子类.

        ``AsyncHTTPClient()`` 实际上是创建一个子类的实例.
        此方法可以使用一个类对象或此类的完全限定名称(或为 ``None`` 则使用默认的,
        ``SimpleAsyncHTTPClient``) 调用.

        如果给定了额外的关键字参数, 它们将会被传递给创建的每个子类实例的
        构造函数. 关键字参数 ``max_clients`` 确定了可以在每个 `.IOLoop` 上
        并行执行的 `~AsyncHTTPClient.fetch()` 操作的最大数量. 根据使用的
        实现类不同, 可能支持其他参数.

        例如::

           AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")
        """
        super(AsyncHTTPClient, cls).configure(impl, **kwargs) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:19,代码来源:httpclient.py

示例4: test_max_clients

# 需要导入模块: from tornado import simple_httpclient [as 别名]
# 或者: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
def test_max_clients(self):
        AsyncHTTPClient.configure(SimpleAsyncHTTPClient)
        with closing(AsyncHTTPClient(
                self.io_loop, force_instance=True)) as client:
            self.assertEqual(client.max_clients, 10)
        with closing(AsyncHTTPClient(
                self.io_loop, max_clients=11, force_instance=True)) as client:
            self.assertEqual(client.max_clients, 11)

        # Now configure max_clients statically and try overriding it
        # with each way max_clients can be passed
        AsyncHTTPClient.configure(SimpleAsyncHTTPClient, max_clients=12)
        with closing(AsyncHTTPClient(
                self.io_loop, force_instance=True)) as client:
            self.assertEqual(client.max_clients, 12)
        with closing(AsyncHTTPClient(
                self.io_loop, max_clients=13, force_instance=True)) as client:
            self.assertEqual(client.max_clients, 13)
        with closing(AsyncHTTPClient(
                self.io_loop, max_clients=14, force_instance=True)) as client:
            self.assertEqual(client.max_clients, 14) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:23,代码来源:simple_httpclient_test.py

示例5: __new__

# 需要导入模块: from tornado import simple_httpclient [as 别名]
# 或者: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
def __new__(cls, force_instance: bool = False, **kwargs: Any) -> "AsyncHTTPClient":
        io_loop = IOLoop.current()
        if force_instance:
            instance_cache = None
        else:
            instance_cache = cls._async_clients()
        if instance_cache is not None and io_loop in instance_cache:
            return instance_cache[io_loop]
        instance = super(AsyncHTTPClient, cls).__new__(cls, **kwargs)  # type: ignore
        # Make sure the instance knows which cache to remove itself from.
        # It can't simply call _async_clients() because we may be in
        # __new__(AsyncHTTPClient) but instance.__class__ may be
        # SimpleAsyncHTTPClient.
        instance._instance_cache = instance_cache
        if instance_cache is not None:
            instance_cache[instance.io_loop] = instance
        return instance 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:19,代码来源:httpclient.py

示例6: configure

# 需要导入模块: from tornado import simple_httpclient [as 别名]
# 或者: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
def configure(
        cls, impl: "Union[None, str, Type[Configurable]]", **kwargs: Any
    ) -> None:
        """Configures the `AsyncHTTPClient` subclass to use.

        ``AsyncHTTPClient()`` actually creates an instance of a subclass.
        This method may be called with either a class object or the
        fully-qualified name of such a class (or ``None`` to use the default,
        ``SimpleAsyncHTTPClient``)

        If additional keyword arguments are given, they will be passed
        to the constructor of each subclass instance created.  The
        keyword argument ``max_clients`` determines the maximum number
        of simultaneous `~AsyncHTTPClient.fetch()` operations that can
        execute in parallel on each `.IOLoop`.  Additional arguments
        may be supported depending on the implementation class in use.

        Example::

           AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")
        """
        super(AsyncHTTPClient, cls).configure(impl, **kwargs) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:24,代码来源:httpclient.py

示例7: configure

# 需要导入模块: from tornado import simple_httpclient [as 别名]
# 或者: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
def configure(cls, impl, **kwargs):
        """Configures the `AsyncHTTPClient` subclass to use.

        ``AsyncHTTPClient()`` actually creates an instance of a subclass.
        This method may be called with either a class object or the
        fully-qualified name of such a class (or ``None`` to use the default,
        ``SimpleAsyncHTTPClient``)

        If additional keyword arguments are given, they will be passed
        to the constructor of each subclass instance created.  The
        keyword argument ``max_clients`` determines the maximum number
        of simultaneous `~AsyncHTTPClient.fetch()` operations that can
        execute in parallel on each `.IOLoop`.  Additional arguments
        may be supported depending on the implementation class in use.

        Example::

           AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")
        """
        super(AsyncHTTPClient, cls).configure(impl, **kwargs) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:22,代码来源:httpclient.py

示例8: __new__

# 需要导入模块: from tornado import simple_httpclient [as 别名]
# 或者: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
def __new__(cls, force_instance=False, **kwargs):
        io_loop = IOLoop.current()
        if force_instance:
            instance_cache = None
        else:
            instance_cache = cls._async_clients()
        if instance_cache is not None and io_loop in instance_cache:
            return instance_cache[io_loop]
        instance = super(AsyncHTTPClient, cls).__new__(cls, **kwargs)
        # Make sure the instance knows which cache to remove itself from.
        # It can't simply call _async_clients() because we may be in
        # __new__(AsyncHTTPClient) but instance.__class__ may be
        # SimpleAsyncHTTPClient.
        instance._instance_cache = instance_cache
        if instance_cache is not None:
            instance_cache[instance.io_loop] = instance
        return instance 
开发者ID:tp4a,项目名称:teleport,代码行数:19,代码来源:httpclient.py

示例9: test_max_clients

# 需要导入模块: from tornado import simple_httpclient [as 别名]
# 或者: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
def test_max_clients(self):
        AsyncHTTPClient.configure(SimpleAsyncHTTPClient)
        with closing(AsyncHTTPClient(force_instance=True)) as client:
            self.assertEqual(client.max_clients, 10)
        with closing(AsyncHTTPClient(
                max_clients=11, force_instance=True)) as client:
            self.assertEqual(client.max_clients, 11)

        # Now configure max_clients statically and try overriding it
        # with each way max_clients can be passed
        AsyncHTTPClient.configure(SimpleAsyncHTTPClient, max_clients=12)
        with closing(AsyncHTTPClient(force_instance=True)) as client:
            self.assertEqual(client.max_clients, 12)
        with closing(AsyncHTTPClient(
                max_clients=13, force_instance=True)) as client:
            self.assertEqual(client.max_clients, 13)
        with closing(AsyncHTTPClient(
                max_clients=14, force_instance=True)) as client:
            self.assertEqual(client.max_clients, 14) 
开发者ID:tp4a,项目名称:teleport,代码行数:21,代码来源:simple_httpclient_test.py

示例10: configurable_default

# 需要导入模块: from tornado import simple_httpclient [as 别名]
# 或者: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
def configurable_default(cls):
        from tornado.simple_httpclient import SimpleAsyncHTTPClient
        return SimpleAsyncHTTPClient 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:5,代码来源:httpclient.py

示例11: get_http_client

# 需要导入模块: from tornado import simple_httpclient [as 别名]
# 或者: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
def get_http_client(self):
        client = SimpleAsyncHTTPClient(io_loop=self.io_loop,
                                       force_instance=True)
        self.assertTrue(isinstance(client, SimpleAsyncHTTPClient))
        return client 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:7,代码来源:simple_httpclient_test.py

示例12: create_client

# 需要导入模块: from tornado import simple_httpclient [as 别名]
# 或者: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
def create_client(self, **kwargs):
        return SimpleAsyncHTTPClient(self.io_loop, force_instance=True,
                                     **kwargs) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:5,代码来源:simple_httpclient_test.py

示例13: setUp

# 需要导入模块: from tornado import simple_httpclient [as 别名]
# 或者: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
def setUp(self):
        super(HostnameMappingTestCase, self).setUp()
        self.http_client = SimpleAsyncHTTPClient(
            self.io_loop,
            hostname_mapping={
                'www.example.com': '127.0.0.1',
                ('foo.example.com', 8000): ('127.0.0.1', self.get_http_port()),
            }) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:10,代码来源:simple_httpclient_test.py

示例14: test_path_traversal_protection

# 需要导入模块: from tornado import simple_httpclient [as 别名]
# 或者: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
def test_path_traversal_protection(self):
        # curl_httpclient processes ".." on the client side, so we
        # must test this with simple_httpclient.
        self.http_client.close()
        self.http_client = SimpleAsyncHTTPClient()
        with ExpectLog(gen_log, ".*not in root static directory"):
            response = self.get_and_head('/static/../static_foo.txt')
        # Attempted path traversal should result in 403, not 200
        # (which means the check failed and the file was served)
        # or 404 (which means that the file didn't exist and
        # is probably a packaging error).
        self.assertEqual(response.code, 403) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:14,代码来源:web_test.py

示例15: get_http_client

# 需要导入模块: from tornado import simple_httpclient [as 别名]
# 或者: from tornado.simple_httpclient import SimpleAsyncHTTPClient [as 别名]
def get_http_client(self):
        # simple_httpclient only: curl doesn't expose the reason string
        return SimpleAsyncHTTPClient(io_loop=self.io_loop) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:5,代码来源:web_test.py


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