本文整理匯總了Python中tornado.httpclient.AsyncHTTPClient.configure方法的典型用法代碼示例。如果您正苦於以下問題:Python AsyncHTTPClient.configure方法的具體用法?Python AsyncHTTPClient.configure怎麽用?Python AsyncHTTPClient.configure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tornado.httpclient.AsyncHTTPClient
的用法示例。
在下文中一共展示了AsyncHTTPClient.configure方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_max_clients
# 需要導入模塊: from tornado.httpclient import AsyncHTTPClient [as 別名]
# 或者: from tornado.httpclient.AsyncHTTPClient import configure [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)
示例2: test_max_clients
# 需要導入模塊: from tornado.httpclient import AsyncHTTPClient [as 別名]
# 或者: from tornado.httpclient.AsyncHTTPClient import configure [as 別名]
def test_max_clients(self):
AsyncHTTPClient.configure(SimpleAsyncHTTPClient)
with closing(AsyncHTTPClient(force_instance=True)) as client:
self.assertEqual(client.max_clients, 10) # type: ignore
with closing(AsyncHTTPClient(max_clients=11, force_instance=True)) as client:
self.assertEqual(client.max_clients, 11) # type: ignore
# 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) # type: ignore
with closing(AsyncHTTPClient(max_clients=13, force_instance=True)) as client:
self.assertEqual(client.max_clients, 13) # type: ignore
with closing(AsyncHTTPClient(max_clients=14, force_instance=True)) as client:
self.assertEqual(client.max_clients, 14) # type: ignore
示例3: test_max_clients
# 需要導入模塊: from tornado.httpclient import AsyncHTTPClient [as 別名]
# 或者: from tornado.httpclient.AsyncHTTPClient import configure [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)
示例4: __aenter__
# 需要導入模塊: from tornado.httpclient import AsyncHTTPClient [as 別名]
# 或者: from tornado.httpclient.AsyncHTTPClient import configure [as 別名]
def __aenter__(self):
await self.hub.initialize([])
await self.hub.start()
# alembic turns off all logs, reenable them for the tests
import logging
from tornado.log import app_log, access_log, gen_log
logs = [app_log, access_log, gen_log, logging.getLogger("DaskGateway")]
for log in logs:
log.disabled = False
# Disable curl http client for easier testing
from tornado.httpclient import AsyncHTTPClient
AsyncHTTPClient.configure("tornado.simple_httpclient.SimpleAsyncHTTPClient")
示例5: _enable_curl_httpclient
# 需要導入模塊: from tornado.httpclient import AsyncHTTPClient [as 別名]
# 或者: from tornado.httpclient.AsyncHTTPClient import configure [as 別名]
def _enable_curl_httpclient(cls):
"""
Tornado proxies are currently only supported with curl_httpclient
http://www.tornadoweb.org/en/stable/httpclient.html#request-objects
"""
if not cls._curl_httpclient_enabled:
AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")
cls._curl_httpclient_enabled = True
示例6: configure_ioloop
# 需要導入模塊: from tornado.httpclient import AsyncHTTPClient [as 別名]
# 或者: from tornado.httpclient.AsyncHTTPClient import configure [as 別名]
def configure_ioloop():
kwargs = {}
if options.ioloop_time_monotonic:
from tornado.platform.auto import monotonic_time
if monotonic_time is None:
raise RuntimeError("monotonic clock not found")
kwargs['time_func'] = monotonic_time
if options.ioloop or kwargs:
IOLoop.configure(options.ioloop, **kwargs)
示例7: client
# 需要導入模塊: from tornado.httpclient import AsyncHTTPClient [as 別名]
# 或者: from tornado.httpclient.AsyncHTTPClient import configure [as 別名]
def client(io_loop, request):
"""Return mocked AsyncHTTPClient"""
before = AsyncHTTPClient.configured_class()
AsyncHTTPClient.configure(MockAsyncHTTPClient)
request.addfinalizer(lambda : AsyncHTTPClient.configure(before))
c = AsyncHTTPClient()
assert isinstance(c, MockAsyncHTTPClient)
return c
示例8: test_max_clients
# 需要導入模塊: from tornado.httpclient import AsyncHTTPClient [as 別名]
# 或者: from tornado.httpclient.AsyncHTTPClient import configure [as 別名]
def test_max_clients(self):
# The max_clients argument is tricky because it was originally
# allowed to be passed positionally; newer arguments are keyword-only.
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, 11, force_instance=True)) as client:
self.assertEqual(client.max_clients, 11)
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)
示例9: config
# 需要導入模塊: from tornado.httpclient import AsyncHTTPClient [as 別名]
# 或者: from tornado.httpclient.AsyncHTTPClient import configure [as 別名]
def config(self):
import forsun
AsyncHTTPClient.configure(None,
max_clients=config.get("ACTION_HTTP_MAX_CLIENTS", 64),
defaults={"user_agent": config.get("ACTION_HTTP_USER_AGENT") or ("forsun/%s" % forsun.version)
})
self.configed = True
示例10: init_pycurl
# 需要導入模塊: from tornado.httpclient import AsyncHTTPClient [as 別名]
# 或者: from tornado.httpclient.AsyncHTTPClient import configure [as 別名]
def init_pycurl(self):
try:
AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")
except ImportError as e:
self.log.debug("Could not load pycurl: %s\npycurl is recommended if you have a large number of users.", e)
# set max verbosity of curl_httpclient at INFO
# because debug-logging from curl_httpclient
# includes every full request and response
if self.log_level < logging.INFO:
curl_log = logging.getLogger('tornado.curl_httpclient')
curl_log.setLevel(logging.INFO)
示例11: mock_asynchttpclient
# 需要導入模塊: from tornado.httpclient import AsyncHTTPClient [as 別名]
# 或者: from tornado.httpclient.AsyncHTTPClient import configure [as 別名]
def mock_asynchttpclient(request):
"""mock AsyncHTTPClient for recording responses"""
AsyncHTTPClient.configure(MockAsyncHTTPClient)
if not os.getenv('GITHUB_ACCESS_TOKEN'):
load_mock_responses('api.github.com')
load_mock_responses('zenodo.org')
示例12: main
# 需要導入模塊: from tornado.httpclient import AsyncHTTPClient [as 別名]
# 或者: from tornado.httpclient.AsyncHTTPClient import configure [as 別名]
def main():
import tornado_http2.test.h2spec_test # for option definitions
define('httpclient', type=str, default=None)
def configure_httpclient():
if options.httpclient is not None:
AsyncHTTPClient.configure(options.httpclient)
else:
AsyncHTTPClient.configure('tornado_http2.client.ForceHTTP2Client')
add_parse_callback(configure_httpclient)
logging.getLogger("tornado.access").setLevel(logging.CRITICAL)
tornado.testing.main()
示例13: initialize
# 需要導入模塊: from tornado.httpclient import AsyncHTTPClient [as 別名]
# 或者: from tornado.httpclient.AsyncHTTPClient import configure [as 別名]
def initialize(self, io_loop, max_clients=10,
hostname_mapping=None, max_buffer_size=104857600,
resolver=None, defaults=None, max_header_size=None,
max_body_size=None):
"""Creates a AsyncHTTPClient.
Only a single AsyncHTTPClient instance exists per IOLoop
in order to provide limitations on the number of pending connections.
``force_instance=True`` may be used to suppress this behavior.
Note that because of this implicit reuse, unless ``force_instance``
is used, only the first call to the constructor actually uses
its arguments. It is recommended to use the ``configure`` method
instead of the constructor to ensure that arguments take effect.
``max_clients`` is the number of concurrent requests that can be
in progress; when this limit is reached additional requests will be
queued. Note that time spent waiting in this queue still counts
against the ``request_timeout``.
``hostname_mapping`` is a dictionary mapping hostnames to IP addresses.
It can be used to make local DNS changes when modifying system-wide
settings like ``/etc/hosts`` is not possible or desirable (e.g. in
unittests).
``max_buffer_size`` (default 100MB) is the number of bytes
that can be read into memory at once. ``max_body_size``
(defaults to ``max_buffer_size``) is the largest response body
that the client will accept. Without a
``streaming_callback``, the smaller of these two limits
applies; with a ``streaming_callback`` only ``max_body_size``
does.
.. versionchanged:: 4.2
Added the ``max_body_size`` argument.
"""
super(SimpleAsyncHTTPClient, self).initialize(io_loop,
defaults=defaults)
self.max_clients = max_clients
self.queue = collections.deque()
self.active = {}
self.waiting = {}
self.max_buffer_size = max_buffer_size
self.max_header_size = max_header_size
self.max_body_size = max_body_size
# TCPClient could create a Resolver for us, but we have to do it
# ourselves to support hostname_mapping.
if resolver:
self.resolver = resolver
self.own_resolver = False
else:
self.resolver = Resolver(io_loop=io_loop)
self.own_resolver = True
if hostname_mapping is not None:
self.resolver = OverrideResolver(resolver=self.resolver,
mapping=hostname_mapping)
self.tcp_client = TCPClient(resolver=self.resolver, io_loop=io_loop)
示例14: initialize
# 需要導入模塊: from tornado.httpclient import AsyncHTTPClient [as 別名]
# 或者: from tornado.httpclient.AsyncHTTPClient import configure [as 別名]
def initialize(self, max_clients=10,
hostname_mapping=None, max_buffer_size=104857600,
resolver=None, defaults=None, max_header_size=None,
max_body_size=None):
"""Creates a AsyncHTTPClient.
Only a single AsyncHTTPClient instance exists per IOLoop
in order to provide limitations on the number of pending connections.
``force_instance=True`` may be used to suppress this behavior.
Note that because of this implicit reuse, unless ``force_instance``
is used, only the first call to the constructor actually uses
its arguments. It is recommended to use the ``configure`` method
instead of the constructor to ensure that arguments take effect.
``max_clients`` is the number of concurrent requests that can be
in progress; when this limit is reached additional requests will be
queued. Note that time spent waiting in this queue still counts
against the ``request_timeout``.
``hostname_mapping`` is a dictionary mapping hostnames to IP addresses.
It can be used to make local DNS changes when modifying system-wide
settings like ``/etc/hosts`` is not possible or desirable (e.g. in
unittests).
``max_buffer_size`` (default 100MB) is the number of bytes
that can be read into memory at once. ``max_body_size``
(defaults to ``max_buffer_size``) is the largest response body
that the client will accept. Without a
``streaming_callback``, the smaller of these two limits
applies; with a ``streaming_callback`` only ``max_body_size``
does.
.. versionchanged:: 4.2
Added the ``max_body_size`` argument.
"""
super(SimpleAsyncHTTPClient, self).initialize(defaults=defaults)
self.max_clients = max_clients
self.queue = collections.deque()
self.active = {}
self.waiting = {}
self.max_buffer_size = max_buffer_size
self.max_header_size = max_header_size
self.max_body_size = max_body_size
# TCPClient could create a Resolver for us, but we have to do it
# ourselves to support hostname_mapping.
if resolver:
self.resolver = resolver
self.own_resolver = False
else:
self.resolver = Resolver()
self.own_resolver = True
if hostname_mapping is not None:
self.resolver = OverrideResolver(resolver=self.resolver,
mapping=hostname_mapping)
self.tcp_client = TCPClient(resolver=self.resolver)
示例15: app
# 需要導入模塊: from tornado.httpclient import AsyncHTTPClient [as 別名]
# 或者: from tornado.httpclient.AsyncHTTPClient import configure [as 別名]
def app(request, io_loop, _binderhub_config):
"""Launch the BinderHub app
Currently reads minikube test config from the repo.
TODO: support input of test config files.
Detects whether kubernetes is available, and if not disables build.
Detects whether jupyterhub is available, and if not disables launch.
app.url will contain the base URL of binderhub.
"""
if REMOTE_BINDER:
app = RemoteBinderHub()
# wait for the remote binder to be up
remaining = 30
deadline = time.monotonic() + remaining
success = False
last_error = None
while remaining:
try:
requests.get(BINDER_URL, timeout=remaining)
except Exception as e:
print(f"Waiting for binder: {e}")
last_error = e
time.sleep(1)
remaining = deadline - time.monotonic()
else:
success = True
break
if not success:
raise last_error
app.url = BINDER_URL
app._configured_bhub = BinderHub(config=_binderhub_config)
return app
if hasattr(request, 'param') and request.param is True:
# load conf for auth test
cfg = PyFileConfigLoader(minikube_testing_auth_config).load_config()
_binderhub_config.merge(cfg)
bhub = BinderHub.instance(config=_binderhub_config)
bhub.initialize([])
bhub.start(run_loop=False)
# instantiating binderhub configures this
# override again
AsyncHTTPClient.configure(MockAsyncHTTPClient)
def cleanup():
bhub.stop()
BinderHub.clear_instance()
request.addfinalizer(cleanup)
# convenience for accessing binder in tests
bhub.url = f'http://127.0.0.1:{bhub.port}{bhub.base_url}'.rstrip('/')
return bhub