本文整理汇总了Python中aiohttp.resolver.AsyncResolver.resolve方法的典型用法代码示例。如果您正苦于以下问题:Python AsyncResolver.resolve方法的具体用法?Python AsyncResolver.resolve怎么用?Python AsyncResolver.resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiohttp.resolver.AsyncResolver
的用法示例。
在下文中一共展示了AsyncResolver.resolve方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_async_resolver_positive_lookup
# 需要导入模块: from aiohttp.resolver import AsyncResolver [as 别名]
# 或者: from aiohttp.resolver.AsyncResolver import resolve [as 别名]
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
# 需要导入模块: from aiohttp.resolver import AsyncResolver [as 别名]
# 或者: from aiohttp.resolver.AsyncResolver import resolve [as 别名]
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
# 需要导入模块: from aiohttp.resolver import AsyncResolver [as 别名]
# 或者: from aiohttp.resolver.AsyncResolver import resolve [as 别名]
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
# 需要导入模块: from aiohttp.resolver import AsyncResolver [as 别名]
# 或者: from aiohttp.resolver.AsyncResolver import resolve [as 别名]
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
# 需要导入模块: from aiohttp.resolver import AsyncResolver [as 别名]
# 或者: from aiohttp.resolver.AsyncResolver import resolve [as 别名]
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
# 需要导入模块: from aiohttp.resolver import AsyncResolver [as 别名]
# 或者: from aiohttp.resolver.AsyncResolver import resolve [as 别名]
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
# 需要导入模块: from aiohttp.resolver import AsyncResolver [as 别名]
# 或者: from aiohttp.resolver.AsyncResolver import resolve [as 别名]
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
# 需要导入模块: from aiohttp.resolver import AsyncResolver [as 别名]
# 或者: from aiohttp.resolver.AsyncResolver import resolve [as 别名]
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
# 需要导入模块: from aiohttp.resolver import AsyncResolver [as 别名]
# 或者: from aiohttp.resolver.AsyncResolver import resolve [as 别名]
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_async_negative_lookup
# 需要导入模块: from aiohttp.resolver import AsyncResolver [as 别名]
# 或者: from aiohttp.resolver.AsyncResolver import resolve [as 别名]
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')
示例11: test_async_resolver_negative_lookup
# 需要导入模块: from aiohttp.resolver import AsyncResolver [as 别名]
# 或者: from aiohttp.resolver.AsyncResolver import resolve [as 别名]
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")