本文整理匯總了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