本文整理汇总了Python中twisted.names.dns.DNSQueryTimeoutError方法的典型用法代码示例。如果您正苦于以下问题:Python dns.DNSQueryTimeoutError方法的具体用法?Python dns.DNSQueryTimeoutError怎么用?Python dns.DNSQueryTimeoutError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.names.dns
的用法示例。
在下文中一共展示了dns.DNSQueryTimeoutError方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getHostByName
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DNSQueryTimeoutError [as 别名]
def getHostByName(name, timeout=None, effort=10):
"""
Resolve a name to a valid ipv4 or ipv6 address.
Will errback with C{DNSQueryTimeoutError} on a timeout, C{DomainError} or
C{AuthoritativeDomainError} (or subclasses) on other errors.
@type name: C{str}
@param name: DNS name to resolve.
@type timeout: Sequence of C{int}
@param timeout: Number of seconds after which to reissue the query.
When the last timeout expires, the query is considered failed.
@type effort: C{int}
@param effort: How many times CNAME and NS records to follow while
resolving this name.
@rtype: C{Deferred}
"""
return getResolver().getHostByName(name, timeout, effort)
示例2: test_queryTimeout
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DNSQueryTimeoutError [as 别名]
def test_queryTimeout(self):
"""
Test that query timeouts after some seconds.
"""
d = self.proto.query(('127.0.0.1', 21345), [dns.Query(b'foo')])
self.assertEqual(len(self.proto.liveMessages), 1)
self.clock.advance(10)
self.assertFailure(d, dns.DNSQueryTimeoutError)
self.assertEqual(len(self.proto.liveMessages), 0)
return d
示例3: _reissue
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DNSQueryTimeoutError [as 别名]
def _reissue(self, reason, addressesLeft, addressesUsed, query, timeout):
reason.trap(dns.DNSQueryTimeoutError)
# If there are no servers left to be tried, adjust the timeout
# to the next longest timeout period and move all the
# "used" addresses back to the list of addresses to try.
if not addressesLeft:
addressesLeft = addressesUsed
addressesLeft.reverse()
addressesUsed = []
timeout = timeout[1:]
# If all timeout values have been used this query has failed. Tell the
# protocol we're giving up on it and return a terminal timeout failure
# to our caller.
if not timeout:
return failure.Failure(defer.TimeoutError(query))
# Get an address to try. Take it out of the list of addresses
# to try and put it ino the list of already tried addresses.
address = addressesLeft.pop()
addressesUsed.append(address)
# Issue a query to a server. Use the current timeout. Add this
# function as a timeout errback in case another retry is required.
d = self._query(address, query, timeout[0], reason.value.id)
d.addErrback(self._reissue, addressesLeft, addressesUsed, query, timeout)
return d
示例4: query
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DNSQueryTimeoutError [as 别名]
def query(self, address, queries, timeout=10, id=None):
self.queries.append((address, queries, timeout, id))
return defer.fail(dns.DNSQueryTimeoutError(queries))
示例5: test_queryTimeout
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DNSQueryTimeoutError [as 别名]
def test_queryTimeout(self):
"""
Test that query timeouts after some seconds.
"""
d = self.proto.query(('127.0.0.1', 21345), [dns.Query('foo')])
self.assertEquals(len(self.proto.liveMessages), 1)
self.clock.advance(10)
self.assertFailure(d, dns.DNSQueryTimeoutError)
self.assertEquals(len(self.proto.liveMessages), 0)
return d
示例6: _reissue
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DNSQueryTimeoutError [as 别名]
def _reissue(self, reason, addressesLeft, addressesUsed, query, timeout):
reason.trap(dns.DNSQueryTimeoutError)
# If there are no servers left to be tried, adjust the timeout
# to the next longest timeout period and move all the
# "used" addresses back to the list of addresses to try.
if not addressesLeft:
addressesLeft = addressesUsed
addressesLeft.reverse()
addressesUsed = []
timeout = timeout[1:]
# If all timeout values have been used, or the protocol has no
# transport, this query has failed. Tell the protocol we're
# giving up on it and return a terminal timeout failure to our
# caller.
if not timeout or self.protocol.transport is None:
self.protocol.removeResend(reason.value.id)
return failure.Failure(defer.TimeoutError(query))
# Get an address to try. Take it out of the list of addresses
# to try and put it ino the list of already tried addresses.
address = addressesLeft.pop()
addressesUsed.append(address)
# Issue a query to a server. Use the current timeout. Add this
# function as a timeout errback in case another retry is required.
d = self.protocol.query(address, query, timeout[0], reason.value.id)
d.addErrback(self._reissue, addressesLeft, addressesUsed, query, timeout)
return d
示例7: _reissue
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DNSQueryTimeoutError [as 别名]
def _reissue(self, reason, address, query, timeout):
reason.trap(dns.DNSQueryTimeoutError)
log.msg('Retrying for %r' % query)
d = self._query(address, query, timeout, reason.value.id)
d.addErrback(self._timeout, query)
return d
示例8: _timeout
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import DNSQueryTimeoutError [as 别名]
def _timeout(self, reason, query):
reason.trap(dns.DNSQueryTimeoutError)
log.msg('Timeout for %r' % query)
log.msg('Given up')
return failure.Failure(defer.TimeoutError(query))