当前位置: 首页>>代码示例>>Python>>正文


Python error.DNSLookupError方法代码示例

本文整理汇总了Python中twisted.internet.error.DNSLookupError方法的典型用法代码示例。如果您正苦于以下问题:Python error.DNSLookupError方法的具体用法?Python error.DNSLookupError怎么用?Python error.DNSLookupError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.internet.error的用法示例。


在下文中一共展示了error.DNSLookupError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: errback_httpbin

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def errback_httpbin(self, failure):
		# log all failures
		self.logger.error(repr(failure))

		# in case you want to do something special for some errors,
		# you may need the failure's type:
		if failure.check(HttpError):
			# these exceptions come from HttpError spider middleware
			# you can get the non-200 response
			response = failure.value.response
			self.logger.error('HttpError on %s', response.url)

		elif failure.check(DNSLookupError):
			# this is the original request
			request = failure.request
			self.logger.error('DNSLookupError on %s', request.url)

		elif failure.check(TimeoutError, TCPTimedOutError):
			request = failure.request
			self.logger.error('TimeoutError on %s', request.url) 
开发者ID:czs0x55aa,项目名称:video_url_crawler_demo,代码行数:22,代码来源:aiqiyi_spider.py

示例2: test_failure

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def test_failure(self):
        """
        L{SimpleResolverComplexifier} translates a known error result from
        L{IResolverSimple.resolveHostName} into an empty result.
        """
        simple = SillyResolverSimple()
        complex = SimpleResolverComplexifier(simple)
        receiver = ResultHolder(self)
        self.assertEqual(receiver._started, False)
        complex.resolveHostName(receiver, u"example.com")
        self.assertEqual(receiver._started, True)
        self.assertEqual(receiver._ended, False)
        self.assertEqual(receiver._addresses, [])
        simple._requests[0].errback(DNSLookupError("nope"))
        self.assertEqual(receiver._ended, True)
        self.assertEqual(receiver._addresses, []) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_resolver.py

示例3: _cbGotServers

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def _cbGotServers(self, result):
        answers, auth, add = result
        if len(answers) == 1 and answers[0].type == dns.SRV \
                             and answers[0].payload \
                             and answers[0].payload.target == dns.Name(b'.'):
            # decidedly not available
            raise error.DNSLookupError("Service %s not available for domain %s."
                                       % (repr(self.service), repr(self.domain)))

        self.servers = []
        self.orderedServers = []
        for a in answers:
            if a.type != dns.SRV or not a.payload:
                continue

            self.orderedServers.append(a.payload) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:srvconnect.py

示例4: test_errorsLogged

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def test_errorsLogged(self):
        """
        Hostname resolution errors are logged.
        """
        mreactor = MemoryReactor()

        clientFactory = object()

        ep, ignoredArgs, ignoredDest = self.createClientEndpoint(
            mreactor, clientFactory)

        def getaddrinfoThatFails(*args, **kwargs):
            raise gaierror(-5, 'No address associated with hostname')

        ep._getaddrinfo = getaddrinfoThatFails

        d = ep.connect(clientFactory)

        self.assertIsInstance(self.failureResultOf(d).value,
                              error.DNSLookupError)
        self.assertEqual(1, len(self.flushLoggedErrors(gaierror))) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:23,代码来源:test_endpoints.py

示例5: connect

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def connect(self):
        """Start connection to remote server."""
        self.factory.doStart()
        self.factory.startedConnecting(self)

        if not self.servers:
            if self.domain is None:
                self.connectionFailed(error.DNSLookupError("Domain is not defined."))
                return
            d = client.lookupService('_%s._%s.%s' %
                    (nativeString(self.service),
                     nativeString(self.protocol),
                     self.domain))
            d.addCallbacks(self._cbGotServers, self._ebGotServers)
            d.addCallback(lambda x, self=self: self._reallyConnect())
            if self._defaultPort:
                d.addErrback(self._ebServiceUnknown)
            d.addErrback(self.connectionFailed)
        elif self.connector is None:
            self._reallyConnect()
        else:
            self.connector.connect() 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:24,代码来源:srvconnect.py

示例6: test_socks5TorStyleFailedResolution

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def test_socks5TorStyleFailedResolution(self):
        """
        A Tor-style name resolution when resolution fails.
        """
        self.assert_handshake()
        self.deliver_data(
            self.sock,
            struct.pack('!BBBB', 5, 0xf0, 0, 3) + struct.pack(
                "!B", len(b"unknown")
            ) + b"unknown" + struct.pack("!H", 3401)
        )
        reply = self.sock.transport.value()
        self.sock.transport.clear()
        self.assertEqual(reply, struct.pack('!BBBB', 5, 4, 0, 0))
        self.assertTrue(self.sock.transport.stringTCPTransport_closing)
        self.assertEqual(len(self.flushLoggedErrors(DNSLookupError)), 1) 
开发者ID:telepresenceio,项目名称:telepresence,代码行数:18,代码来源:test_socks.py

示例7: errback_httpbin

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def errback_httpbin(self, failure):
        # log all failures
        self.logger.error(repr(failure))

        # in case you want to do something special for some errors,
        # you may need the failure's type:

        if failure.check(HttpError):
            print("HttpError出错了")
            # these exceptions come from HttpError spider middleware
            # you can get the non-200 response
            response = failure.value.response
            self.logger.error('HttpError on %s', response.url)

        elif failure.check(DNSLookupError):
            # this is the original request
            request = failure.request
            self.logger.error('DNSLookupError on %s', request.url)

        elif failure.check(TimeoutError, TCPTimedOutError):
            request = failure.request
            self.logger.error('TimeoutError on %s', request.url) 
开发者ID:xugongli,项目名称:poi_spider,代码行数:24,代码来源:test_errorback.py

示例8: connect

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def connect(self):
        """Start connection to remote server."""
        self.factory.doStart()
        self.factory.startedConnecting(self)

        if not self.servers:
            if self.domain is None:
                self.connectionFailed(error.DNSLookupError("Domain is not defined."))
                return
            d = client.lookupService('_%s._%s.%s' % (self.service,
                                                     self.protocol,
                                                     self.domain))
            d.addCallbacks(self._cbGotServers, self._ebGotServers)
            d.addCallback(lambda x, self=self: self._reallyConnect())
            d.addErrback(self.connectionFailed)
        elif self.connector is None:
            self._reallyConnect()
        else:
            self.connector.connect() 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:21,代码来源:srvconnect.py

示例9: resolveHostName

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def resolveHostName(self, resolutionReceiver, hostName, portNumber=0,
                        addressTypes=None, transportSemantics='TCP'):
        """
        See L{IHostnameResolver.resolveHostName}

        @param resolutionReceiver: see interface

        @param hostName: see interface

        @param portNumber: see interface

        @param addressTypes: see interface

        @param transportSemantics: see interface

        @return: see interface
        """
        resolution = HostResolution(hostName)
        resolutionReceiver.resolutionBegan(resolution)
        onAddress = self._simpleResolver.getHostByName(hostName)
        def addressReceived(address):
            resolutionReceiver.addressResolved(IPv4Address('TCP', address,
                                                           portNumber))
        def errorReceived(error):
            if not error.check(DNSLookupError):
                self._log.failure("while looking up {name} with {resolver}",
                                  error, name=hostName,
                                  resolver=self._simpleResolver)
        onAddress.addCallbacks(addressReceived, errorReceived)
        def finish(result):
            resolutionReceiver.resolutionComplete()
        onAddress.addCallback(finish)
        return resolution 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:35,代码来源:_resolver.py

示例10: resolutionComplete

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def resolutionComplete(self):
        """
        See L{IResolutionReceiver.resolutionComplete}
        """
        if self._resolved:
            return
        self._deferred.errback(DNSLookupError(self._resolution.name)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:_resolver.py

示例11: _fail

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def _fail(self, name, err):
        err = error.DNSLookupError("address %r not found: %s" % (name, err))
        return failure.Failure(err) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:5,代码来源:base.py

示例12: getHostByName

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def getHostByName(self, name, timeout = (1, 3, 11, 45)):
        try:
            address = socket.gethostbyname(name)
        except socket.error:
            msg = "address %r not found" % (name,)
            err = error.DNSLookupError(msg)
            return defer.fail(err)
        else:
            return defer.succeed(address) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:base.py

示例13: test_failure

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def test_failure(self):
        """
        L{ThreadedResolver.getHostByName} returns a L{Deferred} which fires a
        L{Failure} if the call to L{socket.gethostbyname} raises an exception.
        """
        timeout = 30

        reactor = FakeReactor()
        self.addCleanup(reactor._stop)

        def fakeGetHostByName(name):
            raise IOError("ENOBUFS (this is a funny joke)")

        self.patch(socket, 'gethostbyname', fakeGetHostByName)

        failedWith = []
        resolver = ThreadedResolver(reactor)
        d = resolver.getHostByName("some.name", (timeout,))
        self.assertFailure(d, DNSLookupError)
        d.addCallback(failedWith.append)

        reactor._runThreadCalls()

        self.assertEqual(len(failedWith), 1)

        # Make sure that any timeout-related stuff gets cleaned up.
        reactor._clock.advance(timeout + 1)
        self.assertEqual(reactor._clock.calls, []) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:30,代码来源:test_base.py

示例14: test_timeout

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def test_timeout(self):
        """
        If L{socket.gethostbyname} does not complete before the specified
        timeout elapsed, the L{Deferred} returned by
        L{ThreadedResolver.getHostByBame} fails with L{DNSLookupError}.
        """
        timeout = 10

        reactor = FakeReactor()
        self.addCleanup(reactor._stop)

        result = Queue()
        def fakeGetHostByName(name):
            raise result.get()

        self.patch(socket, 'gethostbyname', fakeGetHostByName)

        failedWith = []
        resolver = ThreadedResolver(reactor)
        d = resolver.getHostByName("some.name", (timeout,))
        self.assertFailure(d, DNSLookupError)
        d.addCallback(failedWith.append)

        reactor._clock.advance(timeout - 1)
        self.assertEqual(failedWith, [])
        reactor._clock.advance(1)
        self.assertEqual(len(failedWith), 1)

        # Eventually the socket.gethostbyname does finish - in this case, with
        # an exception.  Nobody cares, though.
        result.put(IOError("The I/O was errorful")) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:33,代码来源:test_base.py

示例15: test_failure

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def test_failure(self):
        """
        If no address is returned by GAI for a hostname, the connection attempt
        fails with L{error.DNSLookupError}.
        """
        endpoint = endpoints.HostnameEndpoint(
            deterministicResolvingReactor(Clock(), []),
            b"example.com", 80
        )
        clientFactory = object()
        dConnect = endpoint.connect(clientFactory)
        exc = self.failureResultOf(dConnect, error.DNSLookupError)
        self.assertIn("example.com", str(exc)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:test_endpoints.py


注:本文中的twisted.internet.error.DNSLookupError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。