本文整理汇总了Python中aiohttp.resolver.AsyncResolver类的典型用法代码示例。如果您正苦于以下问题:Python AsyncResolver类的具体用法?Python AsyncResolver怎么用?Python AsyncResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AsyncResolver类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_async_resolver_positive_lookup
def test_async_resolver_positive_lookup(loop):
with patch('aiodns.DNSResolver.query') as mock_query:
mock_query.return_value = fake_result(['127.0.0.1'])
resolver = AsyncResolver(loop=loop)
real = yield from resolver.resolve('www.python.org')
ipaddress.ip_address(real[0]['host'])
mock_query.assert_called_with('www.python.org', 'A')
示例2: test_async_resolver_query_negative_lookup
def test_async_resolver_query_negative_lookup(loop):
with patch('aiodns.DNSResolver') as mock:
del mock().gethostbyname
mock().query.side_effect = aiodns.error.DNSError()
resolver = AsyncResolver(loop=loop)
with pytest.raises(aiodns.error.DNSError):
yield from resolver.resolve('doesnotexist.bla')
示例3: test_async_resolver_positive_lookup
def test_async_resolver_positive_lookup(loop):
with patch("aiodns.DNSResolver") as mock:
mock().gethostbyname.return_value = fake_result(["127.0.0.1"])
resolver = AsyncResolver(loop=loop)
real = yield from resolver.resolve("www.python.org")
ipaddress.ip_address(real[0]["host"])
mock().gethostbyname.assert_called_with("www.python.org", socket.AF_INET)
示例4: test_async_resolver_no_hosts_in_query
def test_async_resolver_no_hosts_in_query(loop):
with patch('aiodns.DNSResolver') as mock:
del mock().gethostbyname
mock().query.return_value = fake_query_result([])
resolver = AsyncResolver(loop=loop)
with pytest.raises(OSError):
yield from resolver.resolve('doesnotexist.bla')
示例5: test_async_resolver_query_multiple_replies
def test_async_resolver_query_multiple_replies(loop):
with patch('aiodns.DNSResolver') as mock:
del mock().gethostbyname
ips = ['127.0.0.1', '127.0.0.2', '127.0.0.3', '127.0.0.4']
mock().query.return_value = fake_query_result(ips)
resolver = AsyncResolver(loop=loop)
real = yield from resolver.resolve('www.google.com')
ips = [ipaddress.ip_address(x['host']) for x in real]
示例6: test_async_resolver_multiple_replies
def test_async_resolver_multiple_replies(loop):
with patch('aiodns.DNSResolver.query') as mock_query:
ips = ['127.0.0.1', '127.0.0.2', '127.0.0.3', '127.0.0.4']
mock_query.return_value = fake_result(ips)
resolver = AsyncResolver(loop=loop)
real = yield from resolver.resolve('www.google.com')
ips = [ipaddress.ip_address(x['host']) for x in real]
assert len(ips) > 3, "Expecting multiple addresses"
示例7: test_async_resolver_query_ipv6_positive_lookup
def test_async_resolver_query_ipv6_positive_lookup(loop):
with patch("aiodns.DNSResolver") as mock:
del mock().gethostbyname
mock().query.return_value = fake_query_result(["::1"])
resolver = AsyncResolver(loop=loop)
real = yield from resolver.resolve("www.python.org", family=socket.AF_INET6)
ipaddress.ip_address(real[0]["host"])
mock().query.assert_called_with("www.python.org", "AAAA")
示例8: test_async_resolver_ipv6_positive_lookup
def test_async_resolver_ipv6_positive_lookup(loop):
with patch('aiodns.DNSResolver') as mock:
mock().gethostbyname.return_value = fake_result(['::1'])
resolver = AsyncResolver(loop=loop)
real = yield from resolver.resolve('www.python.org',
family=socket.AF_INET6)
ipaddress.ip_address(real[0]['host'])
mock().gethostbyname.assert_called_with('www.python.org',
socket.AF_INET6)
示例9: go
def go():
with patch('aiodns.DNSResolver.query') as mock_query:
mock_query.side_effect = aiodns.error.DNSError()
resolver = AsyncResolver(loop=loop)
try:
yield from resolver.resolve('doesnotexist.bla')
assert False, "Expecting aiodns.error.DNSError"
except aiodns.error.DNSError:
pass
示例10: test_close_for_async_resolver
def test_close_for_async_resolver(loop):
resolver = AsyncResolver(loop=loop)
yield from resolver.close()
示例11: test_async_negative_lookup
def test_async_negative_lookup(loop):
with patch('aiodns.DNSResolver.query') as mock_query:
mock_query.side_effect = aiodns.error.DNSError()
resolver = AsyncResolver(loop=loop)
with pytest.raises(aiodns.error.DNSError):
yield from resolver.resolve('doesnotexist.bla')
示例12: test_async_resolver_negative_lookup
def test_async_resolver_negative_lookup(loop):
with patch("aiodns.DNSResolver") as mock:
mock().gethostbyname.side_effect = aiodns.error.DNSError()
resolver = AsyncResolver(loop=loop)
with pytest.raises(aiodns.error.DNSError):
yield from resolver.resolve("doesnotexist.bla")