Python twisted.internet.protocol 模块,connectionDone() 实例源码

我们从Python开源项目中,提取了以下29个代码示例,用于说明如何使用twisted.internet.protocol.connectionDone()

项目:txdarn    作者:markrwilliams    | 项目源码 | 文件源码
def test_connectionLost_clientClose(self):
        '''If connectionLost is called because the client closed the
        connection, then this connection has disappeared suddenly.
        Consequently, the protocol's terminationDeferred errbacks with
        the provided reason, the timeout clock is stopped, and the
        session machine learns about the lost connection.

        '''
        erroredDeferred = self.protocol.terminationDeferred

        def trapConnectionDone(failure):
            failure.trap(error.ConnectionDone)

        erroredDeferred.addErrback(trapConnectionDone)

        self.protocol.connectionLost(connectionDone)

        self.assertEqual(self.timeoutClockRecorder.stopCalls, 1)
        self.assertEqual(self.sessionMachineRecorder.connectionsLostReasons,
                         [connectionDone])
        self.assertIsNone(self.protocol.sessionMachine)

        return erroredDeferred
项目:marathon-acme    作者:praekeltfoundation    | 项目源码 | 文件源码
def connectionLost(self, reason=connectionDone):
        self.log.failure('SSE connection lost', reason, LogLevel.warn)
        self.setTimeout(None)  # Cancel the timeout
        for d in list(self._waiting):
            d.callback(None)
        self._waiting = []
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def loseConnection(self):
        self.proto.connectionLost(protocol.connectionDone)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def connectionLost(self, reason=protocol.connectionDone):
        """We are no longer connected"""
        self.setTimeout(None)
        self.mailFile = None
项目:onkyo_serial    作者:blaedd    | 项目源码 | 文件源码
def connectionLost(self, reason=protocol.connectionDone):
        self.factory.remove_cb(self)
项目:onkyo_serial    作者:blaedd    | 项目源码 | 文件源码
def connectionLost(self, reason=protocol.connectionDone):
        self.factory.remove_cb(self)
项目:ircproto    作者:agronholm    | 项目源码 | 文件源码
def connectionLost(self, reason=connectionDone):
        reactor.stop()
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def loseConnection(self):
        self.proto.connectionLost(protocol.connectionDone)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def connectionLost(self, reason=protocol.connectionDone):
        """We are no longer connected"""
        self.setTimeout(None)
        self.mailFile = None
项目:Parlay    作者:PromenadeSoftware    | 项目源码 | 文件源码
def connectionLost(self, reason=connectionDone):
        """
        Overridden function that is called when the connected port is disconnected. Simply sets the
        self.is_port_attached flag to False so that we know we have been disconnected from the target embedded
        board.
        :param reason: Reason for disconnection. Of Twisted failure type.
        :return:
        """
        self.is_port_attached = False
        LineReceiver.connectionLost(self, reason)
项目:matrix-appservice-gitter-twisted    作者:remram44    | 项目源码 | 文件源码
def connectionLost(self, reason=connectionDone):
        log.info("Lost stream for user {user} room {room}",
                 user=self.user.github_username, room=self.gitter_room_name)
        self.stream_response = None
        if not self.destroyed:
            gitter_stream_limit.schedule(self.start_stream)
项目:matrix-appservice-gitter-twisted    作者:remram44    | 项目源码 | 文件源码
def connectionLost(self, reason=connectionDone):
        if not self.finished.called:
            self.finished.callback(self.content.getvalue())
项目:joinmarket-clientserver    作者:JoinMarket-Org    | 项目源码 | 文件源码
def connectionLost(self, reason=protocol.connectionDone):
        if self.wrapper.on_disconnect:
            reactor.callLater(0.0, self.wrapper.on_disconnect, self.wrapper)
        return irc.IRCClient.connectionLost(self, reason)
项目:treadmill    作者:Morgan-Stanley    | 项目源码 | 文件源码
def connectionLost(self, reason=protocol.connectionDone):
        """Callback invoked on connection lost."""
        _LOGGER.info('connection lost')
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def loseConnection(self):
        self.proto.connectionLost(protocol.connectionDone)
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def connectionLost(self, reason=protocol.connectionDone):
        """
        We are no longer connected
        """
        self.setTimeout(None)
        self.mailFile = None
项目:txdarn    作者:markrwilliams    | 项目源码 | 文件源码
def test_beginRequest_finishedNotifier_forwards_failures(self):
        '''Beginning a request retrieves a Deferred from that request that
        forwards failures to the protocol's connectionLost.

        '''
        self.protocol.request = self.request
        self.protocol.beginRequest()

        reason = connectionDone

        def assertConnectionLostCalled(ignored):
            recordedExceptions = [
                reason.value for reason in
                self.sessionMachineRecorder.connectionsLostReasons]
            self.assertEqual(recordedExceptions, [reason.value])

        finishedNotifier = self.protocol.finishedNotifier
        finishedNotifier.addCallback(assertConnectionLostCalled)

        def trapConnectionDone(failure):
            failure.trap(error.ConnectionDone)

        terminationDeferred = self.protocol.terminationDeferred
        terminationDeferred.addErrback(trapConnectionDone)

        self.request.processingFailed(reason)
        return DeferredList([finishedNotifier, terminationDeferred])
项目:txdarn    作者:markrwilliams    | 项目源码 | 文件源码
def test_completeConnectionLost(self):
        '''Completing a lost connection calls the wrapped protocol's
        connectionLost.

        '''
        self.request.transport = StringTransport()
        self.protocol.establishConnection(self.request)
        self.protocol.completeConnectionLost(connectionDone)
        self.assertEqual(self.connectionsLost, [connectionDone])
项目:txdarn    作者:markrwilliams    | 项目源码 | 文件源码
def test_timedOutCallback(self):
        '''The termination deferred's callback sets disconnecting and calls
        connectionLost.  Setting disconnecting avoids errbacking the
        deferred that's just been fired!

        '''
        terminationDeferred = self.protocol.terminationDeferred

        def assertConnectionLostCalled(ignored):
            self.assertTrue(self.protocol.disconnecting)
            self.assertEqual(self.sessionMachineRecorder.connectionsLost,
                             connectionDone)

        terminationDeferred.callback(P.TimeoutClock.EXPIRED)
        return terminationDeferred
项目:txdarn    作者:markrwilliams    | 项目源码 | 文件源码
def test_sessionClosed_on_errback(self):
        '''Errbacking the protocol's terminationDeferred removes the session
        from the house.

        '''
        self.test_attachToSession_new_session()
        self.protocol.terminationDeferred.errback(connectionDone)
        self.assertNotIn(self.sessionID, self.sessions.sessions)
        return self.protocol.terminationDeferred
项目:txdarn    作者:markrwilliams    | 项目源码 | 文件源码
def connectionLost(self, reason=protocol.connectionDone):
        '''The connection has been lost; clean up any request and clean up the
        protocol.

        '''
项目:txdarn    作者:markrwilliams    | 项目源码 | 文件源码
def _dropRequest(self, reason=protocol.connectionDone):
        self.requestSession.request = None
项目:txdarn    作者:markrwilliams    | 项目源码 | 文件源码
def _closeProtocol(self, reason=protocol.connectionDone):
        self.requestSession.completeConnectionLost(reason)
        self.requestSession = None
项目:txdarn    作者:markrwilliams    | 项目源码 | 文件源码
def _timedOut(self, reason=protocol.connectionDone):
        if isinstance(reason.value, error.ConnectionDone):
            reason = failure.Failure(SessionTimeout())
        self.requestSession.completeConnectionLost(reason=reason)
        self.requestSession = None
项目:txdarn    作者:markrwilliams    | 项目源码 | 文件源码
def connectionLost(self, reason=protocol.connectionDone):
        if not self.disconnecting:
            self.terminationDeferred.errback(reason)
            self.timeoutClock.stop()
        self.sessionMachine.connectionLost(reason)
        self.sessionMachine = None
项目:duct    作者:ducted    | 项目源码 | 文件源码
def connectionLost(self, reason=protocol.connectionDone):
        self.stdOut.seek(0)
        self.stdErr.seek(0)
        if reason.type is error.ConnectionDone:
            # Success
            code = 0
        else:
            code = reason.value.exitCode
        self.factory.done.callback((self.stdOut, self.stdErr, code))
项目:pokelector    作者:Kostronor    | 项目源码 | 文件源码
def connectionLost(self, reason=connectionDone):
        self.session.commit()
        self.session.close()
        self.update_tick(dot='-')
项目:maas    作者:maas    | 项目源码 | 文件源码
def test_onConnectionLost_fires_when_connection_is_lost(self):
        protocol = common.RPCProtocol()
        protocol.makeConnection(StringTransport())
        protocol.connectionLost(connectionDone)
        self.assertThat(protocol.onConnectionLost, IsFiredDeferred())
项目:QRL    作者:theQRL    | 项目源码 | 文件源码
def connectionLost(self, reason=connectionDone):
        logger.info('%s disconnected. remainder connected: %s',
                    self.transport.getPeer().host,
                    str(self.factory.connections))  # , reason
        try:
            self.factory.peer_connections.remove(self)

            if self.factory.connections == 0:
                reactor.callLater(60, self.factory.connect_peers)

            # FIXME: unsafe access to synced_peers
            if self in self.factory.synced_peers:
                self.factory.synced_peers.remove(self)
        except Exception:
            pass