How to use the twisted.python.failure.Failure function in Twisted

To help you get started, we’ve selected a few Twisted examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github twisted / twisted / sandbox / slyphon / ftp_refactor / test_ftp.py View on Github external
def cleanup(self):
        self.c.connectionLost(failure.Failure(main.CONNECTION_DONE))
        self.s.connectionLost(failure.Failure(main.CONNECTION_DONE))
        reactor.iterate() # last gasp before I go away
github coherence-project / Coherence / coherence / backends / flickr_storage.py View on Github external
def upnp_ImportResource(self, *args, **kwargs):
        print 'upnp_ImportResource', args, kwargs
        SourceURI = kwargs['SourceURI']
        DestinationURI = kwargs['DestinationURI']

        if DestinationURI.endswith('?import'):
            id = DestinationURI.split('/')[-1]
            id = id[:-7]  # remove the ?import
        else:
            return failure.Failure(errorCode(718))

        item = self.get_by_id(id)
        if item == None:
            return failure.Failure(errorCode(718))

        def gotPage(result):

            try:
                import cStringIO as StringIO
            except ImportError:
                import StringIO

            self.backend_import(item, StringIO.StringIO(result[0]))

        def gotError(error, url):
            self.warning("error requesting %s", url)
            self.info(error)
            return failure.Failure(errorCode(718))

        d = getPage(SourceURI)
github twisted / twisted / twisted / internet / javareactor.py View on Github external
def block(self):
        if self.consuming:
            try:
                data = self.fdes.writeQ.get_nowait()
            except Queue.Empty:
                self.producing = 0
                self.q.put((self.fdes.produceMore, 1))
                data = self.fdes.writeQ.get()
        else:
            data = self.fdes.writeQ.get()
        if data is None:
            self.stop()
            return (self.fdes.connectionLost, failure.Failure())
        elif data == BEGIN_CONSUMING:
            self.consuming = 1
        elif data == END_CONSUMING:
            self.consuming = 0
        else:
            # bytes = jarray.array(map(ord, data), 'b')
            try:
                self.fdes.ostream.write(data)
                self.fdes.ostream.flush()
            except SocketException:
                self.stop()
                return (self.fdes.connectionLost, failure.Failure())
github nskinkel / oppy / oppy / connection / connectionbuildtask.py View on Github external
def _connectionFailed(self, reason):
        msg = ("Authentication handshake to {} failed. Reason: {}."
               .format(self.micro_status_entry.fingerprint, reason))
        logging.debug(msg)
        if self._failed is False:
            self._failed = True
            self.transport.abortConnection()
        self._connection_manager.connectionTaskFailed(
            self, Failure(Exception(reason)))
github matthew-humphrey / treater / Lib / treater / camera.py View on Github external
def errbackDefers(self, failure):
        defers = self.defers
        self.defers = []
        for d in defers:
            if not d.called:
                d.errback(Failure())
github cowrie / cowrie / src / cowrie / core / checkers.py View on Github external
def requestAvatarId(self, credentials):
        _pubKey = keys.Key.fromString(credentials.blob)
        log.msg(eventid='cowrie.client.fingerprint',
                format='public key attempt for user %(username)s of type %(type)s with fingerprint %(fingerprint)s',
                username=credentials.username,
                fingerprint=_pubKey.fingerprint(),
                key=_pubKey.toString('OPENSSH'),
                type=_pubKey.sshType())

        return failure.Failure(error.ConchError('Incorrect signature'))
github nskinkel / oppy / oppy / connection / connectionbuildtask.py View on Github external
def connectionMade(self):
        msg = "Connection made to {}.".format(self.micro_status_entry.address)
        logging.debug(msg)
        try:
            self._tasks = self._sendVersionsCell()
            self._tasks.addCallback(self._processVersionsCell)
            self._tasks.addCallback(self._processCertsCell)
            self._tasks.addCallback(self._processAuthChallengeCell)
            self._tasks.addCallback(self._processNetInfoCell)
            self._tasks.addCallback(self._sendNetInfoCell)
            self._tasks.addCallback(self._connectionSucceeded)
            self._tasks.addErrback(self._connectionFailed)
        except Exception as e:
            self._connectionFailed(Failure(e))
github LeastAuthority / leastauthority.com / lae_util / k8s_cert_store.py View on Github external
            lambda body: Failure(Exception(response.code, body)),
        )