def test_SRVNoService(self):
"""
Test that connecting fails when no service is present.
"""
payload = dns.Record_SRV(port=5269, target=b'.', ttl=60)
client.theResolver.results = [dns.RRHeader(name='example.org',
type=dns.SRV,
cls=dns.IN, ttl=60,
payload=payload)]
self.connector.connect()
self.assertIsNotNone(self.factory.reason)
self.factory.reason.trap(DNSLookupError)
self.assertEqual(self.reactor.tcpClients, [])
python类DNSLookupError()的实例源码
def _cbRecords(self, records, name, effort):
(ans, auth, add) = records
result = extractRecord(self, dns.Name(name), ans + auth + add, effort)
if not result:
raise error.DNSLookupError(name)
return result
def testSimpleFailureWithFallback(self):
return self.assertFailure(self.mx.getMX('test.domain'), DNSLookupError)
def test_do_failing_request(self):
http_test = httpt.HTTPTest()
http_test.localOptions['socksproxy'] = None
http_test._setUp()
yield self.assertFailure(http_test.doRequest('http://invaliddomain/'), DNSLookupError)
assert http_test.report['requests'][0]['failure'] == 'dns_lookup_error'
def test_hostname_does_not_resolve(self):
"""
Specifying a hostname which cannot be resolved to an
IP address will result in an ``DNSLookupError``.
"""
with ExpectedException(DNSLookupError, "DNS lookup failed: no results "
"for hostname lookup: doesnotresolve."):
self._authorized_request(
token="test",
headers=Headers({}),
kubernetes_host=b"doesnotresolve"
)
def _ebMX(self, failure, domain):
"""
Attempt to use the name of the domain directly when mail exchange
lookup fails.
@type failure: L{Failure}
@param failure: The reason for the lookup failure.
@type domain: L{bytes}
@param domain: The domain name.
@rtype: L{Record_MX <twisted.names.dns.Record_MX>} or L{Failure}
@return: An MX record for the domain or a failure if the fallback to
domain option is not in effect and an error, other than not
finding an MX record, occurred during lookup.
@raise IOError: When no MX record could be found and the fallback to
domain option is not in effect.
@raise DNSLookupError: When no MX record could be found and the
fallback to domain option is in effect but no address for the
domain could be found.
"""
from twisted.names import error, dns
if self.fallbackToDomain:
failure.trap(error.DNSNameError)
log.msg("MX lookup failed; attempting to use hostname (%s) directly" % (domain,))
# Alright, I admit, this is a bit icky.
d = self.resolver.getHostByName(domain)
def cbResolved(addr):
return dns.Record_MX(name=addr)
def ebResolved(err):
err.trap(error.DNSNameError)
raise DNSLookupError()
d.addCallbacks(cbResolved, ebResolved)
return d
elif failure.check(error.DNSNameError):
raise IOError("No MX found for %r" % (domain,))
return failure