コード例 #1
0
ファイル: dispatcher.py プロジェクト: shnoppel/mediaproxy
 def _relay_error(self, failure, try_relays, command):
     failure.trap(RelayError)
     failed_relay = try_relays.popleft()
     failed_relay.logger.warning(
         'The {0.name!r} request failed: {1.value}'.format(
             command, failure))
     return self._try_next(try_relays, command)
コード例 #2
0
ファイル: command.py プロジェクト: TheProjecter/tops
	def error_callback(self,failure,payload):
		try:
			failure.trap(CommandException)
			# the next line will only run if failure is a CommandException
			self.args = payload
		except twisted.python.failure.Failure:
			pass
コード例 #3
0
 def _trap_nosuchcodeimportjob(self, failure):
     failure.trap(xmlrpc.Fault)
     if failure.value.faultCode == NoSuchCodeImportJob.error_code:
         self._call_finish_job = False
         raise ExitQuietly
     else:
         raise failure.value
コード例 #4
0
 def _trap_nosuchcodeimportjob(self, failure):
     failure.trap(xmlrpc.Fault)
     if failure.value.faultCode == NoSuchCodeImportJob.error_code:
         self._call_finish_job = False
         raise ExitQuietly
     else:
         raise failure.value
コード例 #5
0
ファイル: gsioc.py プロジェクト: marcosfelt/octopus
 def error(failure, try_again=0):
     if try_again is not 0:
         failure.trap(BufferedCommandFailed)
         d = task.deferLater(reactor, 0.2, fn, id, command)
         d.addCallbacks(next,
                        error,
                        errbackKeywords={"try_again": try_again - 1})
         return d
コード例 #6
0
 def _errback(self, failure: Failure) -> None:
     # This gets called on any exceptions in aiterator.__anext__().
     # It handles StopAsyncIteration by stopping the iteration and reraises all others.
     self.anext_deferred = None
     failure.trap(StopAsyncIteration)
     self.finished = True
     for d in self.waiting_deferreds:
         d.callback(None)
コード例 #7
0
ファイル: protocol.py プロジェクト: hhco/txdarn
 def _sessionClosed(self, maybeFailure, sessionID):
     del self.sessions[sessionID]
     if isinstance(maybeFailure, failure.Failure):
         failure.trap(error.ConnectionDone,
                      error.ConnectionLost,
                      SessionTimeout)
     else:
         return maybeFailure
コード例 #8
0
ファイル: websocket.py プロジェクト: ncalexan/autopush
    def err_overload(self, failure, message_type):
        """Handle database overloads

        Pause producing to cease incoming notifications while we wait a random
        interval up to 8 seconds before closing down the connection. Most
        clients wait up to 10 seconds for a command, but this is not a
        guarantee, so rather than never reply, we still shut the connection
        down.

        """
        failure.trap(ProvisionedThroughputExceededException)
        self.transport.pauseProducing()
        d = self.deferToLater(random.randrange(4, 9), self.err_finish_overload, message_type)
        d.addErrback(self.trap_cancel)
コード例 #9
0
ファイル: resolver.py プロジェクト: jjmojojjmojo/awsdns
 def relookup(failure):
     failure.trap(error.DNSNameError)
     
     if type == dns.PTR:
         ip = self._reverse_ip(name)
         d = threads.deferToThread(self._ec2.get_all_instances, filters={self.reverse_filter: ip})
         d.addCallback(self.create_message, name, self.forward_filter, record=dns.PTR)
     elif type == dns.A:
         d = threads.deferToThread(self._ec2.get_all_instances, filters={self.forward_filter: str(name)})
         d.addCallback(self.create_message, name, self.reverse_filter, record=dns.A)
     else:
         raise ValueError, "Record constant '%s' is not supported" % (type)
         
     return d
コード例 #10
0
    def err_overload(self, failure, message_type):
        """Handle database overloads

        Pause producing to cease incoming notifications while we wait a random
        interval up to 8 seconds before closing down the connection. Most
        clients wait up to 10 seconds for a command, but this is not a
        guarantee, so rather than never reply, we still shut the connection
        down.

        """
        failure.trap(ProvisionedThroughputExceededException)
        self.transport.pauseProducing()
        d = self.deferToLater(random.randrange(4, 9), self.err_finish_overload,
                              message_type)
        d.addErrback(self.trap_cancel)
コード例 #11
0
ファイル: torconfig.py プロジェクト: gsathya/txtorcon
    def _retry_local_port(self, failure):
        """
        Handles :api:`twisted.internet.error.CannotListenError` by
        trying again on another port. After 10 failures, we give up
        and propogate the error.
        """
        failure.trap(error.CannotListenError)

        self.retries += 1
        if self.retries > 10:
            return failure
        self.listen_port = self.port_generator()
        ## we do want to overwrite the whole list, not append
        self.hiddenservice.ports = ['%d 127.0.0.1:%d' % (self.public_port, self.listen_port)]
        d = self.config.save()
        d.addCallback(self._create_listener).addErrback(self._retry_local_port)
        return d
コード例 #12
0
ファイル: firewall.py プロジェクト: pombredanne/spamfighter
    def _label_helper(self, failure, debug=False):
        """
        Errback, который ловит L{SkipToProcess}, чтобы обеcпечить остановку
        на нужном label после skip to.
        @param debug: включить отладочный режим?
        @type debug: C{bool}
        """
        failure.trap(SkipToProcess)

        if failure.value.label != self.label:
            if debug:
                failure.value.pack.debug("Labels for skip don't match %d != %d" % (failure.value.label, self.label))
            return failure

        if debug:
            failure.value.pack.debug("Stopped skip to at label %d" % self.label)

        return failure.value.pack
コード例 #13
0
ファイル: test_client.py プロジェクト: hugovk/twisted
    def _ebRoundRobinBackoff(self, failure, fakeProto):
        failure.trap(defer.TimeoutError)

        # Assert that each server is tried with a particular timeout
        # before the timeout is increased and the attempts are repeated.

        for t in (1, 3, 11, 45):
            tries = fakeProto.queries[: len(self.testServers)]
            del fakeProto.queries[: len(self.testServers)]

            tries.sort()
            expected = list(self.testServers)
            expected.sort()

            for ((addr, query, timeout, id), expectedAddr) in zip(tries, expected):
                self.assertEqual(addr, (expectedAddr, 53))
                self.assertEqual(timeout, t)

        self.assertFalse(fakeProto.queries)
コード例 #14
0
 def test_invalid_domain(self):
     """Tests sending to a domain we don't have mappings for."""
     rcpt = smtp.User("*****@*****.**", None, object(), self.sender)
     ret = self._sendMessage(rcpt, False)
     ret.addCallbacks(self.fail,
                      lambda failure: failure.trap(smtp.SMTPBadRcpt))
     ret.addCallback(self._checkLogs,
                     [("user", "invaliddomain.com", logging.ERROR,
                       str(self.sender), str(rcpt.dest), 0)])
     return ret
コード例 #15
0
ファイル: test_names.py プロジェクト: Almad/twisted
    def _ebRoundRobinBackoff(self, failure, fakeProto):
        failure.trap(defer.TimeoutError)

        # Assert that each server is tried with a particular timeout
        # before the timeout is increased and the attempts are repeated.

        for t in (1, 3, 11, 45):
            tries = fakeProto.queries[:len(self.testServers)]
            del fakeProto.queries[:len(self.testServers)]

            tries.sort()
            expected = list(self.testServers)
            expected.sort()

            for ((addr, query, timeout, id), expectedAddr) in zip(tries, expected):
                self.assertEquals(addr, (expectedAddr, 53))
                self.assertEquals(timeout, t)

        self.failIf(fakeProto.queries)
コード例 #16
0
ファイル: test_component_feed.py プロジェクト: flyapen/UgFlu
        def loginFailed(failure):
            def gotRoot(root):
                # an idempotent method, should return a network failure if
                # the remote side disconnects as it should
                return root.callRemote("getKeycardClasses")

            def gotError(failure):
                self.assertAdditionalFDsOpen(1, "feedSent (socket)")
                self.info("success")

            def gotKeycardClasses(classes):
                raise AssertionError("should not get here")

            self.info("loginFailed: %s", log.getFailureMessage(failure))
            failure.trap(errors.NotAuthenticatedError)
            d = factory.getRootObject()  # should fire immediately
            d.addCallback(gotRoot)
            d.addCallbacks(gotKeycardClasses, gotError)

            return d
コード例 #17
0
        def loginFailed(failure):
            def gotRoot(root):
                # an idempotent method, should return a network failure if
                # the remote side disconnects as it should
                return root.callRemote('getKeycardClasses')

            def gotError(failure):
                self.assertAdditionalFDsOpen(1, 'feedSent (socket)')
                self.info('success')

            def gotKeycardClasses(classes):
                raise AssertionError('should not get here')

            self.info('loginFailed: %s', log.getFailureMessage(failure))
            failure.trap(errors.NotAuthenticatedError)
            d = factory.getRootObject()  # should fire immediately
            d.addCallback(gotRoot)
            d.addCallbacks(gotKeycardClasses, gotError)

            return d
コード例 #18
0
 def test_invalid_address(self):
     """Tests sending to an invalid address."""
     rcpt = smtp.User("*****@*****.**", None, object(),
                      self.sender)
     ret = self._sendMessage(rcpt, False)
     ret.addCallbacks(self.fail,
                      lambda failure: failure.trap(smtp.SMTPBadRcpt))
     ret.addCallback(self._checkLogs,
                     [("doesnotexist", "smtp2web.com", logging.ERROR,
                       str(self.sender), str(rcpt.dest), 0)])
     return ret
コード例 #19
0
ファイル: server_test.py プロジェクト: andola-dev/smtp2web
 def test_invalid_domain(self):
   """Tests sending to a domain we don't have mappings for."""
   rcpt = smtp.User("*****@*****.**", None, object(), self.sender)
   ret = self._sendMessage(rcpt, False)
   ret.addCallbacks(
       self.fail,
       lambda failure: failure.trap(smtp.SMTPBadRcpt)
   )
   ret.addCallback(self._checkLogs, [("user", "invaliddomain.com",
                   logging.ERROR, str(self.sender), str(rcpt.dest), 0)])
   return ret
コード例 #20
0
ファイル: server_test.py プロジェクト: andola-dev/smtp2web
 def test_invalid_address(self):
   """Tests sending to an invalid address."""
   rcpt = smtp.User("*****@*****.**", None, object(), self.sender)
   ret = self._sendMessage(rcpt, False)
   ret.addCallbacks(
       self.fail,
       lambda failure: failure.trap(smtp.SMTPBadRcpt)
   )
   ret.addCallback(self._checkLogs, [("doesnotexist", "smtp2web.com",
                   logging.ERROR, str(self.sender), str(rcpt.dest), 0)])
   return ret
コード例 #21
0
ファイル: server_test.py プロジェクト: andola-dev/smtp2web
 def test_send_fail(self):
   """Tests sending with a handler that raises an exception."""
   rcpt = smtp.User("*****@*****.**", None, object(), self.sender)
   ret = self._sendMessage(rcpt)
   ret.addCallbacks(
       self.fail,
       lambda failure: failure.trap(smtp2web.MessageSubmissionError)
   )
   handler = self.settings.usermap['smtp2web.com'].findHandler("fail")
   ret.addCallback(lambda x: self.failUnlessEqual(handler.invocations,
                   [(str(self.sender), str(rcpt.dest), self.test_message)]))
   ret.addCallback(self._checkLogs, [("fail", "smtp2web.com", logging.ERROR,
                   str(self.sender), str(rcpt.dest), len(self.test_message))])
   return ret
コード例 #22
0
        def relookup(failure):
            failure.trap(error.DNSNameError)

            if type == dns.PTR:
                ip = self._reverse_ip(name)
                d = threads.deferToThread(self._ec2.get_all_instances,
                                          filters={self.reverse_filter: ip})
                d.addCallback(self.create_message,
                              name,
                              self.forward_filter,
                              record=dns.PTR)
            elif type == dns.A:
                d = threads.deferToThread(
                    self._ec2.get_all_instances,
                    filters={self.forward_filter: str(name)})
                d.addCallback(self.create_message,
                              name,
                              self.reverse_filter,
                              record=dns.A)
            else:
                raise ValueError, "Record constant '%s' is not supported" % (
                    type)

            return d
コード例 #23
0
    def __checkJobStepResults(self, failure, status):
        "Check that given self.js.status is set to correct value after certain JobStep operation"
        twisted_logger.writeLog(self.logPrefix, None, "Checking test results...")

        if failure is not None:
            error = failure.getErrorMessage()
            failure.trap(RuntimeError)
            print "ERROR: %s" % error
        else:
            error = None
            
        query = "select status, text_input, error, start_time, end_time from scs.job_step " \
                "where job_id = %d and step_id = %d" % (self.js.jobID, self.js.stepID) 
        res = synchdb.query(query)
        db_status, text_input, db_error, start_time, end_time = res[0]

        self.assertEquals(str(self.js.input), text_input, "<scs.job_step> text_input ('%s') not equals to expected input ('%s')" % (text_input, str(self.js.input)))
        self.assertEquals(error, db_error, "<scs.job_step> error ('%s') not equals to expected error ('%s')" % (db_error, error))
        self.assertEquals(status, db_status, "<scs.job_step> status ('%s') not equals to expected status ('%s')" % (db_status, status))
        self.assertEquals(self.js.status, status, "<js.status> ('%s') not equals to expected status ('%s')" % (self.js.status, status))
        if self.js.status != 'RUNNING':
            self.assertNotEquals(end_time, None)
            
        twisted_logger.writeLog(self.logPrefix, None, "Test succeeded!")
コード例 #24
0
ファイル: retry.py プロジェクト: SUNET/lobber-storagenode
 def __call__(self, failure):
     r = failure.trap(weberror.Error,error.ConnectionRefusedError)
     
     if r == error.ConnectionRefusedError:
         status = int(http.INTERNAL_SERVER_ERROR)
     else:
         status = int(failure.value.status)
     
     if status == http.NOT_FOUND:
         if self.seen404:
             return failure
         else:
             self.seen404 = True
     elif status not in self.okErrs:
         return failure
コード例 #25
0
 def test_send_fail(self):
     """Tests sending with a handler that raises an exception."""
     rcpt = smtp.User("*****@*****.**", None, object(), self.sender)
     ret = self._sendMessage(rcpt)
     ret.addCallbacks(
         self.fail,
         lambda failure: failure.trap(smtp2web.MessageSubmissionError))
     handler = self.settings.usermap['smtp2web.com'].findHandler("fail")
     ret.addCallback(lambda x: self.failUnlessEqual(handler.invocations, [(
         str(self.sender), str(rcpt.dest), self.test_message)]))
     ret.addCallback(
         self._checkLogs,
         [("fail", "smtp2web.com", logging.ERROR, str(
             self.sender), str(rcpt.dest), len(self.test_message))])
     return ret
コード例 #26
0
 def maybe_make_branch_in_db(failure):
     # Looks like we are trying to make a branch.
     failure.trap(NoSuchFile)
     return self.server.createBranch(self._abspath(relpath))
コード例 #27
0
ファイル: dispatcher.py プロジェクト: shnoppel/mediaproxy
 def _error_handler(self, failure):
     failure.trap(CommandError, RelayError)
     self.logger.error(failure.value)
     self.reply('error')
コード例 #28
0
    def defaultErrback(self, failure):
        """TODO better network error handling.
	"""
        failure.trap(ConnectionAborted, ConnectionClosed,
                     ConnectionDone, ConnectionLost)
コード例 #29
0
ファイル: firewall.py プロジェクト: pombredanne/spamfighter
 def handleAttributeKeyError(failure):
     """
     Обрабатываем исключение об отсутствии атрибута у сообщения.
     """
     failure.trap(AttributeNotFoundError)
     raise errors.MessageAttributeKeyException, failure.value.args[0]
コード例 #30
0
ファイル: dispatch.py プロジェクト: DxCx/twimp
 def _remote_abort_handler_eb(self, failure):
     failure.trap(CallAbortedException)
     # log failure but do nothing more
     log.debug('remote call aborted: %s', failure.value)
コード例 #31
0
ファイル: relay.py プロジェクト: tmhenry/mediaproxy
 def _eb_no_srv(self, failure, addr, port):
     failure.trap(DomainError)
     return reactor.resolve(addr).addCallback(lambda host: (host, port)).addErrback(self._eb_no_dns, addr)
コード例 #32
0
ファイル: dnsserver.py プロジェクト: 0x333333/smart_dns
 def __call__(self, failure):
     # AuthoritativeDomainErrors should halt resolution attempts
     failure.trap(dns.DomainError, defer.TimeoutError, NotImplementedError)
     return self.resolver(self.query, self.timeout, self.addr, self.edns)
コード例 #33
0
 def _authenticatedErrback(self, failure, request):
     failure.trap(errors.NotAuthenticatedError)
     self._handleUnauthorized(request, http.UNAUTHORIZED)
     return failure
コード例 #34
0
ファイル: component.py プロジェクト: ylatuya/Flumotion
 def eb(failure):
     if failure.trap(errors.ComponentMoodError):
         common.errorRaise("Component '%s' is in the wrong mood." %
             self.parentCommand.componentId)
     else:
         common.errorRaise(log.getFailureMessage(failure))
コード例 #35
0
ファイル: component.py プロジェクト: ylatuya/Flumotion
 def _errback(self, failure):
     failure.trap(errors.SleepingComponentError)
     common.errorRaise("Component '%s' is sleeping." %
         self.parentCommand.componentId)
コード例 #36
0
 def try_second_key(failure):
     failure.trap(UnauthorizedLogin)
     return checker.requestAvatarId(right_key_creds)
コード例 #37
0
 def _silenceQuietExit(self, failure):
     """Quietly swallow a ExitQuietly failure."""
     failure.trap(ExitQuietly)
     return None
コード例 #38
0
ファイル: xmlrpc.py プロジェクト: Ri0n/rcore
 def checkConnection(failure):
     failure.trap(ConnectionRefusedError)
     print "trying next proxy if available"
     self.__class__._needNextProxy = True
     return Service.__call__(self, *params).addErrback(checkConnection)
コード例 #39
0
ファイル: dnsserver.py プロジェクト: hwy10/smartdns
 def __call__(self, failure):
     # AuthoritativeDomainErrors should halt resolution attempts
     failure.trap(dns.DomainError, defer.TimeoutError, NotImplementedError)
     return self.resolver(self.query, self.timeout, self.addr, self.edns)
コード例 #40
0
ファイル: firewall.py プロジェクト: pombredanne/spamfighter
 def processSkipThrough(failure):
     """
     Обрабатываем ситуацию, когда для skip to.. не нашлось метки.
     """
     failure.trap(SkipToProcess)
     raise errors.SkipToFallthroughError(failure.value.label)
コード例 #41
0
 def handleEOF(self, failure, remoteFd, localFd):
     failure.trap(exceptions.EOFError)
     #self.factory.runner.log("download completed")
     return remoteFd
コード例 #42
0
 def noPostProcessor(failure, report):
     failure.trap(e.NoPostProcessor)
     return report
コード例 #43
0
 def _checkFailure(failure):
     failure.trap(smtp.SMTPServerError)
     self.failUnlessEqual(failure.value.code, 552)
コード例 #44
0
 def p(failure):
     failure.trap(ftp.CommandFailed)
コード例 #45
0
 def defaultErrback(self, failure):
     #see testing note above
     failure.trap(ConnectionAborted, ConnectionClosed, ConnectionDone,
                  ConnectionLost) #pragma: no cover
コード例 #46
0
ファイル: firewall.py プロジェクト: pombredanne/spamfighter
 def handleDomainKeyError(failure):
     """
     Обрабатываем отсутствующий ключ в домене, на который "напоролось" правило.
     """
     failure.trap(DomainKeyError)
     raise errors.AttributeKeyException, failure.value.args[0]
コード例 #47
0
 def defaultErrback(self, failure):
     failure.trap(ConnectionAborted, ConnectionClosed, ConnectionDone, ConnectionLost)
コード例 #48
0
 def checkNotImplemented(failure):
     failure.trap(NotImplementedError)
     raise error.StanzaError('feature-not-implemented')
コード例 #49
0
ファイル: relay.py プロジェクト: tmhenry/mediaproxy
 def _eb_no_dns(self, failure, addr):
     failure.trap(DNSLookupError)
     log.error("Could resolve neither SRV nor A record for '%s'" % addr)
コード例 #50
0
 def p(failure):
     # Make sure we got the failure we were expecting.
     failure.trap(ftp.CommandFailed)
コード例 #51
0
 def _ebLogin(failure):
     failure.trap(cred_error.UnauthorizedLogin,
                  cred_error.UnhandledCredentials)
     self.state = self.UNAUTH
     raise AuthorizationError
コード例 #52
0
ファイル: gsioc.py プロジェクト: rasata/octopus
		def error (failure, try_again = 0):
			if try_again is not 0:
				failure.trap(BufferedCommandFailed)
				d = task.deferLater(reactor, 0.2, fn, id, command)
				d.addCallbacks(next, error, errbackKeywords = { "try_again": try_again - 1 })
				return d
コード例 #53
0
ファイル: test_proxy.py プロジェクト: asa-Q/asa
 def trap(self, failure, what):
     failure.trap(what)
コード例 #54
0
 def _eb_no_srv(self, failure, addr, port):
     failure.trap(DomainError)
     return reactor.resolve(addr).addCallback(
         lambda host: (host, port)).addErrback(self._eb_no_dns, addr)
コード例 #55
0
 def defaultErrback(self, failure):
     failure.trap(ConnectionAborted, ConnectionClosed, ConnectionDone,
                  ConnectionLost, UnknownRemoteError)
     reactor.stop()
コード例 #56
0
 def _eb_no_dns(self, failure, addr):
     failure.trap(DNSLookupError)
     log.error("Could resolve neither SRV nor A record for '%s'" % addr)
コード例 #57
0
ファイル: http.py プロジェクト: ylatuya/Flumotion
 def _authenticatedErrback(self, failure, request):
     failure.trap(errors.UnknownComponentError,
                  errors.NotAuthenticatedError)
     self._handleUnauthorized(request, http.UNAUTHORIZED)
     return failure
コード例 #58
0
 def fromStanzaError(failure, iq):
     failure.trap(error.StanzaError)
     return failure.value.toResponse(iq)