本文整理汇总了Python中twisted.names.client.getResolver方法的典型用法代码示例。如果您正苦于以下问题:Python client.getResolver方法的具体用法?Python client.getResolver怎么用?Python client.getResolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.names.client
的用法示例。
在下文中一共展示了client.getResolver方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_interface
# 需要导入模块: from twisted.names import client [as 别名]
# 或者: from twisted.names.client import getResolver [as 别名]
def test_interface(self):
"""
L{client.getResolver} returns an object providing L{IResolver}.
"""
with AlternateReactor(Clock()):
resolver = client.getResolver()
self.assertTrue(verifyObject(IResolver, resolver))
示例2: test_idempotent
# 需要导入模块: from twisted.names import client [as 别名]
# 或者: from twisted.names.client import getResolver [as 别名]
def test_idempotent(self):
"""
Multiple calls to L{client.getResolver} return the same L{IResolver}
implementation.
"""
with AlternateReactor(Clock()):
a = client.getResolver()
b = client.getResolver()
self.assertIs(a, b)
示例3: _initResolver
# 需要导入模块: from twisted.names import client [as 别名]
# 或者: from twisted.names.client import getResolver [as 别名]
def _initResolver():
global DebugResolver
if DebugResolver is None:
if config.Scheduling.iSchedule.DNSDebug:
DebugResolver = FakeBindAuthority(config.Scheduling.iSchedule.DNSDebug)
else:
DebugResolver = getResolver()
示例4: __init__
# 需要导入模块: from twisted.names import client [as 别名]
# 或者: from twisted.names.client import getResolver [as 别名]
def __init__(self):
self.recs = {}
self.resolver = client.getResolver()
示例5: reverseResolve
# 需要导入模块: from twisted.names import client [as 别名]
# 或者: from twisted.names.client import getResolver [as 别名]
def reverseResolve(
ip: MaybeIPAddress, resolver: IResolver = None
) -> Optional[List[str]]:
"""Using the specified IResolver, reverse-resolves the specifed `ip`.
:return: a sorted list of resolved hostnames (which the specified IP
address reverse-resolves to). If the DNS lookup appeared to succeed,
but no hostnames were found, returns an empty list. If the DNS lookup
timed out or an error occurred, returns None.
"""
if resolver is None:
resolver = getResolver()
ip = IPAddress(ip)
try:
data = yield resolver.lookupPointer(
ip.reverse_dns, timeout=REVERSE_RESOLVE_RETRIES
)
# I love the concise way in which I can ask the Twisted data structure
# what the list of hostnames is. This is great.
results = sorted(
(rr.payload.name.name.decode("idna") for rr in data[0]),
key=preferred_hostnames_sort_key,
)
except AuthoritativeDomainError:
# "Failed to reverse-resolve '%s': authoritative failure." % ip
# This means the name didn't resolve, so return an empty list.
return []
except DomainError:
# "Failed to reverse-resolve '%s': no records found." % ip
# This means the name didn't resolve, so return an empty list.
return []
except DNSQueryTimeoutError:
# "Failed to reverse-resolve '%s': timed out." % ip
# Don't return an empty list since this implies a temporary failure.
pass
except ResolverError:
# "Failed to reverse-resolve '%s': rejected by local resolver." % ip
# Don't return an empty list since this could be temporary (unclear).
pass
else:
return results
return None