本文整理汇总了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()
示例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
示例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)
示例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)
示例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
示例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)
示例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)
示例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
示例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)
示例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
示例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
示例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)
示例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()),
})
示例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)
示例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)