本文整理汇总了Python中tornado.netutil.Resolver方法的典型用法代码示例。如果您正苦于以下问题:Python netutil.Resolver方法的具体用法?Python netutil.Resolver怎么用?Python netutil.Resolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.netutil
的用法示例。
在下文中一共展示了netutil.Resolver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import Resolver [as 别名]
def __init__(self, io_loop, request):
self.connect_future = TracebackFuture()
self.read_future = None
self.read_queue = collections.deque()
self.key = base64.b64encode(os.urandom(16))
scheme, sep, rest = request.url.partition(':')
scheme = {'ws': 'http', 'wss': 'https'}[scheme]
request.url = scheme + sep + rest
request.headers.update({
'Upgrade': 'websocket',
'Connection': 'Upgrade',
'Sec-WebSocket-Key': self.key,
'Sec-WebSocket-Version': '13',
})
self.resolver = Resolver(io_loop=io_loop)
super(WebSocketClientConnection, self).__init__(
io_loop, None, request, lambda: None, self._on_http_response,
104857600, self.resolver)
示例2: raw_fetch
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import Resolver [as 别名]
def raw_fetch(self, headers, body):
with closing(Resolver(io_loop=self.io_loop)) as resolver:
with closing(SimpleAsyncHTTPClient(self.io_loop,
resolver=resolver)) as client:
conn = RawRequestHTTPConnection(
self.io_loop, client,
httpclient._RequestProxy(
httpclient.HTTPRequest(self.get_url("/")),
dict(httpclient.HTTPRequest._DEFAULTS)),
None, self.stop,
1024 * 1024, resolver)
conn.set_request(
b"\r\n".join(headers +
[utf8("Content-Length: %d\r\n" % len(body))]) +
b"\r\n" + body)
response = self.wait()
response.rethrow()
return response
示例3: initialize
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import Resolver [as 别名]
def initialize(self, io_loop=None):
self.io_loop = io_loop or IOLoop.current()
# partial copy of twisted.names.client.createResolver, which doesn't
# allow for a reactor to be passed in.
self.reactor = tornado.platform.twisted.TornadoReactor(io_loop)
host_resolver = twisted.names.hosts.Resolver('/etc/hosts')
cache_resolver = twisted.names.cache.CacheResolver(reactor=self.reactor)
real_resolver = twisted.names.client.Resolver('/etc/resolv.conf',
reactor=self.reactor)
self.resolver = twisted.names.resolve.ResolverChain(
[host_resolver, cache_resolver, real_resolver])
示例4: __init__
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import Resolver [as 别名]
def __init__(self, resolver=None, io_loop=None):
self.io_loop = io_loop or IOLoop.current()
if resolver is not None:
self.resolver = resolver
self._own_resolver = False
else:
self.resolver = Resolver(io_loop=io_loop)
self._own_resolver = True
示例5: setUp
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import Resolver [as 别名]
def setUp(self):
# Dummy Resolver subclass that never invokes its callback.
class BadResolver(Resolver):
def resolve(self, *args, **kwargs):
pass
super(ResolveTimeoutTestCase, self).setUp()
self.http_client = SimpleAsyncHTTPClient(
self.io_loop,
resolver=BadResolver())
示例6: main
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import Resolver [as 别名]
def main():
args = parse_command_line()
if not args:
args = ['localhost', 'www.google.com',
'www.facebook.com', 'www.dropbox.com']
resolvers = [Resolver(), ThreadedResolver()]
if twisted is not None:
from tornado.platform.twisted import TwistedResolver
resolvers.append(TwistedResolver())
if pycares is not None:
from tornado.platform.caresresolver import CaresResolver
resolvers.append(CaresResolver())
family = {
'unspec': socket.AF_UNSPEC,
'inet': socket.AF_INET,
'inet6': socket.AF_INET6,
}[options.family]
for host in args:
print('Resolving %s' % host)
for resolver in resolvers:
addrinfo = yield resolver.resolve(host, 80, family)
print('%s: %s' % (resolver.__class__.__name__,
pprint.pformat(addrinfo)))
print()
示例7: __init__
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import Resolver [as 别名]
def __init__(self, sock):
self._iostream = IOStream(sock)
self._resolver = Resolver()
self._readtimeout = 0
self._connecttimeout = 0
self._rbuffer = StringIO(b'')
self._rbuffer_size = 0
示例8: initialize
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import Resolver [as 别名]
def initialize(self) -> None:
# partial copy of twisted.names.client.createResolver, which doesn't
# allow for a reactor to be passed in.
self.reactor = twisted.internet.asyncioreactor.AsyncioSelectorReactor()
host_resolver = twisted.names.hosts.Resolver("/etc/hosts")
cache_resolver = twisted.names.cache.CacheResolver(reactor=self.reactor)
real_resolver = twisted.names.client.Resolver(
"/etc/resolv.conf", reactor=self.reactor
)
self.resolver = twisted.names.resolve.ResolverChain(
[host_resolver, cache_resolver, real_resolver]
)
示例9: __init__
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import Resolver [as 别名]
def __init__(self, resolver: Resolver = None) -> None:
if resolver is not None:
self.resolver = resolver
self._own_resolver = False
else:
self.resolver = Resolver()
self._own_resolver = True
示例10: test_connect_timeout
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import Resolver [as 别名]
def test_connect_timeout(self):
timeout = 0.1
cleanup_event = Event()
test = self
class TimeoutResolver(Resolver):
async def resolve(self, *args, **kwargs):
await cleanup_event.wait()
# Return something valid so the test doesn't raise during shutdown.
return [(socket.AF_INET, ("127.0.0.1", test.get_http_port()))]
with closing(self.create_client(resolver=TimeoutResolver())) as client:
with self.assertRaises(HTTPTimeoutError):
yield client.fetch(
self.get_url("/hello"),
connect_timeout=timeout,
request_timeout=3600,
raise_error=True,
)
# Let the hanging coroutine clean up after itself. We need to
# wait more than a single IOLoop iteration for the SSL case,
# which logs errors on unexpected EOF.
cleanup_event.set()
yield gen.sleep(0.2)
示例11: setUp
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import Resolver [as 别名]
def setUp(self):
self.cleanup_event = Event()
test = self
# Dummy Resolver subclass that never finishes.
class BadResolver(Resolver):
@gen.coroutine
def resolve(self, *args, **kwargs):
yield test.cleanup_event.wait()
# Return something valid so the test doesn't raise during cleanup.
return [(socket.AF_INET, ("127.0.0.1", test.get_http_port()))]
super(ResolveTimeoutTestCase, self).setUp()
self.http_client = SimpleAsyncHTTPClient(resolver=BadResolver())
示例12: initialize
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import Resolver [as 别名]
def initialize(self, io_loop, max_clients=10,
hostname_mapping=None, max_buffer_size=104857600,
resolver=None, defaults=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.
max_clients is the number of concurrent requests that can be
in progress. Note that this arguments are only used when the
client is first created, and will be ignored when an existing
client is reused.
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 is the number of bytes that can be read by IOStream. It
defaults to 100mb.
"""
super(SimpleAsyncHTTPClient, self).initialize(io_loop,
defaults=defaults)
self.max_clients = max_clients
self.queue = collections.deque()
self.active = {}
self.max_buffer_size = max_buffer_size
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)
示例13: initialize
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import Resolver [as 别名]
def initialize(self):
# partial copy of twisted.names.client.createResolver, which doesn't
# allow for a reactor to be passed in.
self.reactor = tornado.platform.twisted.TornadoReactor()
host_resolver = twisted.names.hosts.Resolver('/etc/hosts')
cache_resolver = twisted.names.cache.CacheResolver(reactor=self.reactor)
real_resolver = twisted.names.client.Resolver('/etc/resolv.conf',
reactor=self.reactor)
self.resolver = twisted.names.resolve.ResolverChain(
[host_resolver, cache_resolver, real_resolver])
示例14: __init__
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import Resolver [as 别名]
def __init__(self, resolver=None):
if resolver is not None:
self.resolver = resolver
self._own_resolver = False
else:
self.resolver = Resolver()
self._own_resolver = True
示例15: test_connect_timeout
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import Resolver [as 别名]
def test_connect_timeout(self):
timeout = 0.1
class TimeoutResolver(Resolver):
def resolve(self, *args, **kwargs):
return Future() # never completes
with closing(self.create_client(resolver=TimeoutResolver())) as client:
with self.assertRaises(HTTPTimeoutError):
yield client.fetch(self.get_url('/hello'),
connect_timeout=timeout,
request_timeout=3600,
raise_error=True)