當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。