python类DNSLookupError()的实例源码

test_srvconnect.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
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, [])
common.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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
test_mail.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def testSimpleFailureWithFallback(self):
        return self.assertFailure(self.mx.getMX('test.domain'), DNSLookupError)
test_templates.py 文件源码 项目:ooniprobe-debian 作者: TheTorProject 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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'
test_authentication.py 文件源码 项目:txkube 作者: LeastAuthority 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
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"
            )
relaymanager.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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


问题


面经


文章

微信
公众号

扫码关注公众号