コード例 #1
0
ファイル: socksclient.py プロジェクト: miadz/twisted-socks
 def createWrappingFactory(f):
     """
     Wrap creation of _WrappingFactory since __init__() doesn't
     take a canceller as of Twisted 12.1 or something.
     """
     if len(inspect.getargspec(_WrappingFactory.__init__)[0]) == 3:
         def _canceller(deferred):
             connector.stopConnecting()
             deferred.errback(
                 error.ConnectingCancelledError(
                     connector.getDestination()))
         return _WrappingFactory(f, _canceller)
     else:                           # Twisted >= 12.1.
         return _WrappingFactory(f)
コード例 #2
0
ファイル: socksclient.py プロジェクト: kloesing/twisted-socks
        def createWrappingFactory(f):
            """
            Wrap creation of _WrappingFactory since __init__() doesn't
            take a canceller as of Twisted 12.1 or something.
            """
            if len(inspect.getargspec(_WrappingFactory.__init__)[0]) == 3:

                def _canceller(deferred):
                    connector.stopConnecting()
                    deferred.errback(error.ConnectingCancelledError(connector.getDestination()))

                return _WrappingFactory(f, _canceller)
            else:  # Twisted >= 12.1.
                return _WrappingFactory(f)
コード例 #3
0
ファイル: test_endpoints.py プロジェクト: Berimor66/mythbox
    def test_failedBuildProtocol(self):
        """
        An exception raised in C{buildProtocol} of our wrappedFactory
        results in our C{onConnection} errback being fired.
        """

        class BogusFactory(ClientFactory):
            """
            A one off factory whose C{buildProtocol} raises an C{Exception}.
            """

            def buildProtocol(self, addr):
                raise ValueError("My protocol is poorly defined.")


        wf = endpoints._WrappingFactory(BogusFactory(), None)

        wf.buildProtocol(None)

        d = self.assertFailure(wf._onConnection, ValueError)
        d.addCallback(lambda e: self.assertEquals(
                e.args,
                ("My protocol is poorly defined.",)))

        return d
コード例 #4
0
ファイル: test_endpoints.py プロジェクト: debedb/kupuestra2
    def test_failedBuildProtocol(self):
        """
        An exception raised in C{buildProtocol} of our wrappedFactory
        results in our C{onConnection} errback being fired.
        """

        class BogusFactory(ClientFactory):
            """
            A one off factory whose C{buildProtocol} raises an C{Exception}.
            """

            def buildProtocol(self, addr):
                raise ValueError("My protocol is poorly defined.")


        wf = endpoints._WrappingFactory(BogusFactory(), None)

        wf.buildProtocol(None)

        d = self.assertFailure(wf._onConnection, ValueError)
        d.addCallback(lambda e: self.assertEqual(
                e.args,
                ("My protocol is poorly defined.",)))

        return d
コード例 #5
0
ファイル: test_endpoints.py プロジェクト: debedb/kupuestra2
 def test_logPrefixPassthrough(self):
     """
     If the wrapped protocol provides L{ILoggingContext}, whatever is
     returned from the wrapped C{logPrefix} method is returned from
     L{_WrappingProtocol.logPrefix}.
     """
     wf = endpoints._WrappingFactory(TestFactory(), None)
     wp = wf.buildProtocol(None)
     self.assertEqual(wp.logPrefix(), "A Test Protocol")
コード例 #6
0
ファイル: test_endpoints.py プロジェクト: debedb/kupuestra2
 def test_doStart(self):
     """
     L{_WrappingFactory.doStart} passes through to the wrapped factory's
     C{doStart} method, allowing application-specific setup and logging.
     """
     factory = ClientFactory()
     wf = endpoints._WrappingFactory(factory, None)
     wf.doStart()
     self.assertEqual(1, factory.numPorts)
コード例 #7
0
ファイル: Ssh2Telnet.py プロジェクト: matanmaz/SshTelnetProxy
 def connect(self, protocolFactory):
     """
     Implement L{IStreamClientEndpoint.connect} to connect via TCP.
     """
     try:
         wf = _WrappingFactory(protocolFactory)
         self.agent = Agent(self._reactor)
         return wf._onConnection
     except:
         return defer.fail()
コード例 #8
0
    def test_wrappedProtocolConnectionLost(self):
        """
        Our wrappedProtocol's connectionLost method is called when
        L{_WrappingProtocol.connectionLost} is called.
        """
        tf = TestFactory()
        wf = endpoints._WrappingFactory(tf, None)
        p = wf.buildProtocol(None)

        p.connectionLost("fail")

        self.assertEquals(p._wrappedProtocol.connectionsLost, ["fail"])
コード例 #9
0
ファイル: lirc.py プロジェクト: blaedd/onkyo_serial
 def connect(self, protocolFactory):
     # noinspection PyBroadException
     try:
         wf = endpoints._WrappingFactory(protocolFactory)
         reader = LircReader(self._program_name, self._lirc_config,
                             self._reactor)
         reader.protocol = wf.buildProtocol(None)
         reader.protocol.transport = reader
         reader.startReading()
         return wf._onConnection
     except:
         return defer.fail()
コード例 #10
0
ファイル: test_endpoints.py プロジェクト: Berimor66/mythbox
    def test_wrappedProtocolConnectionLost(self):
        """
        Our wrappedProtocol's connectionLost method is called when
        L{_WrappingProtocol.connectionLost} is called.
        """
        tf = TestFactory()
        wf = endpoints._WrappingFactory(tf, None)
        p = wf.buildProtocol(None)

        p.connectionLost("fail")

        self.assertEquals(p._wrappedProtocol.connectionsLost, ["fail"])
コード例 #11
0
ファイル: test_endpoints.py プロジェクト: debedb/kupuestra2
 def test_logPrefixDefault(self):
     """
     If the wrapped protocol does not provide L{ILoggingContext}, the wrapped
     protocol's class name is returned from L{_WrappingProtocol.logPrefix}.
     """
     class NoProtocol(object):
         pass
     factory = TestFactory()
     factory.protocol = NoProtocol
     wf = endpoints._WrappingFactory(factory, None)
     wp = wf.buildProtocol(None)
     self.assertEqual(wp.logPrefix(), "NoProtocol")
コード例 #12
0
ファイル: endpoints.py プロジェクト: Izeni/ParselTONE
    def connect(self, protocolFactory):
        def _canceller(deferred):
            connector.stopConnecting()
            deferred.errback(
                error.ConnectingCancelledError(connector.getDestination()))

        try:
            wf = _WrappingFactory(protocolFactory, _canceller)
            connector = SRVConnector(self._reactor, self._service, 
                self._domain, wf, protocol=self._protocol)
            connector.connect()
            return wf._onConnection
        except:
            return defer.fail()
コード例 #13
0
    def test_wrappedProtocolDataReceived(self):
        """
        The wrapped C{Protocol}'s C{dataReceived} will get called when our
        C{_WrappingProtocol}'s C{dataReceived} gets called.
        """
        wf = endpoints._WrappingFactory(TestFactory(), None)
        p = wf.buildProtocol(None)
        p.makeConnection(None)

        p.dataReceived('foo')
        self.assertEquals(p._wrappedProtocol.data, ['foo'])

        p.dataReceived('bar')
        self.assertEquals(p._wrappedProtocol.data, ['foo', 'bar'])
コード例 #14
0
ファイル: test_endpoints.py プロジェクト: Berimor66/mythbox
    def test_wrappedProtocolDataReceived(self):
        """
        The wrapped C{Protocol}'s C{dataReceived} will get called when our
        C{_WrappingProtocol}'s C{dataReceived} gets called.
        """
        wf = endpoints._WrappingFactory(TestFactory(), None)
        p = wf.buildProtocol(None)
        p.makeConnection(None)

        p.dataReceived('foo')
        self.assertEquals(p._wrappedProtocol.data, ['foo'])

        p.dataReceived('bar')
        self.assertEquals(p._wrappedProtocol.data, ['foo', 'bar'])
コード例 #15
0
 def connect(self, factory):
     tls_factory = tls.TLSMemoryBIOFactory(self._server_options,
                                           isClient=False,
                                           wrappedFactory=factory)
     try:
         wf = _WrappingFactory(tls_factory)
         self._reactor.connectTCP(self._host,
                                  self._port,
                                  wf,
                                  timeout=self._timeout,
                                  bindAddress=self._bindAddress)
         return wf._onConnection
     except:
         return defer.fail()
コード例 #16
0
ファイル: endpoint.py プロジェクト: sporsh/carnifex
 def _connectRelay(self, process, protocolFactory):
     """Set up and connect the protocol we want to relay to the process.
     This method is automatically called when the process is started,
     and we are ready to relay through it.
     """
     try:
         wf = _WrappingFactory(protocolFactory)
         connector = RelayConnector(process, wf, self.timeout,
                                    self.inductor.reactor)
         connector.connect()
     except:
         return defer.fail()
     # Return a deferred that is called back when the protocol is connected.
     return wf._onConnection
コード例 #17
0
    def test_wrappedProtocolTransport(self):
        """
        Our transport is properly hooked up to the wrappedProtocol when a
        connection is made.
        """
        wf = endpoints._WrappingFactory(TestFactory(), None)
        p = wf.buildProtocol(None)

        dummyTransport = object()

        p.makeConnection(dummyTransport)

        self.assertEquals(p.transport, dummyTransport)

        self.assertEquals(p._wrappedProtocol.transport, dummyTransport)
コード例 #18
0
ファイル: test_endpoints.py プロジェクト: Berimor66/mythbox
    def test_wrappedProtocolTransport(self):
        """
        Our transport is properly hooked up to the wrappedProtocol when a
        connection is made.
        """
        wf = endpoints._WrappingFactory(TestFactory(), None)
        p = wf.buildProtocol(None)

        dummyTransport = object()

        p.makeConnection(dummyTransport)

        self.assertEquals(p.transport, dummyTransport)

        self.assertEquals(p._wrappedProtocol.transport, dummyTransport)
コード例 #19
0
    def connect(self, protocolFactory):
        """
        Return a deferred firing when the SOCKS connection is established.
        """

        try:
            # Connect with an intermediate SOCKS factory/protocol,
            # which then hands control to the provided protocolFactory
            # once a SOCKS connection has been established.
            f = self.factory()
            f.postHandshakeEndpoint = self._endpoint
            f.postHandshakeFactory = protocolFactory
            f.handshakeDone = defer.Deferred()
            wf = _WrappingFactory(f)
            self._reactor.connectTCP(self._host, self._port, wf)
            return f.handshakeDone
        except:
            return defer.fail()
コード例 #20
0
    def connect(self, protocolFactory):
        """
        Return a deferred firing when the SOCKS connection is established.
        """

        try:
            # Connect with an intermediate SOCKS factory/protocol,
            # which then hands control to the provided protocolFactory
            # once a SOCKS connection has been established.
            f = self.factory()
            f.postHandshakeEndpoint = self._endpoint
            f.postHandshakeFactory = protocolFactory
            f.handshakeDone = defer.Deferred()
            wf = _WrappingFactory(f)
            self._reactor.connectTCP(self._host, self._port, wf)
            return f.handshakeDone
        except: 
            return defer.fail() 
コード例 #21
0
    def test_clientConnectionFailed(self):
        """
        Calls to L{_WrappingFactory.clientConnectionLost} should errback the
        L{_WrappingFactory._onConnection} L{Deferred}
        """
        wf = endpoints._WrappingFactory(TestFactory(), None)
        expectedFailure = Failure(error.ConnectError(string="fail"))

        wf.clientConnectionFailed(None, expectedFailure)

        errors = []

        def gotError(f):
            errors.append(f)

        wf._onConnection.addErrback(gotError)

        self.assertEquals(errors, [expectedFailure])
コード例 #22
0
ファイル: test_endpoints.py プロジェクト: Berimor66/mythbox
    def test_clientConnectionFailed(self):
        """
        Calls to L{_WrappingFactory.clientConnectionLost} should errback the
        L{_WrappingFactory._onConnection} L{Deferred}
        """
        wf = endpoints._WrappingFactory(TestFactory(), None)
        expectedFailure = Failure(error.ConnectError(string="fail"))

        wf.clientConnectionFailed(
            None,
            expectedFailure)

        errors = []
        def gotError(f):
            errors.append(f)

        wf._onConnection.addErrback(gotError)

        self.assertEquals(errors, [expectedFailure])
コード例 #23
0
ファイル: socksclient.py プロジェクト: jagtesh/twisted-socks
    def connect(self, protocolFactory):
        """
        Return a deferred firing when the SOCKS connection is established.
        """

        def _canceller(deferred):
            connector.stopConnecting()
            deferred.errback(
		error.ConnectingCancelledError(connector.getDestination()))

        try:
            # Connect with an intermediate SOCKS factory/protocol,
            # which then hands control to the provided protocolFactory
            # once a SOCKS connection has been established.
            f = self.factory()
            f.protocol.postHandshakeEndpoint = self._endpoint
            f.protocol.postHandshakeFactory = protocolFactory
            f.protocol.handshakeDone = defer.Deferred()
            wf = _WrappingFactory(f, _canceller)
            self._reactor.connectTCP(self._host, self._port, wf)
            return f.protocol.handshakeDone
        except: 
            return defer.fail() 
コード例 #24
0
 def connect(self, protocolFactory):
     wf = _WrappingFactory(protocolFactory)
     connector = StringTransportConnector(
         self._string_transport, wf, self._reactor)
     connector.connect()
     return wf._onConnection
コード例 #25
0
 def connect(self, protocolFactory):
     wf = _WrappingFactory(protocolFactory)
     connector = StringTransportConnector(self._string_transport, wf,
                                          self._reactor)
     connector.connect()
     return wf._onConnection