当前位置: 首页>>代码示例>>Python>>正文


Python StringTransportWithDisconnection.protocol方法代码示例

本文整理汇总了Python中twisted.test.proto_helpers.StringTransportWithDisconnection.protocol方法的典型用法代码示例。如果您正苦于以下问题:Python StringTransportWithDisconnection.protocol方法的具体用法?Python StringTransportWithDisconnection.protocol怎么用?Python StringTransportWithDisconnection.protocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.test.proto_helpers.StringTransportWithDisconnection的用法示例。


在下文中一共展示了StringTransportWithDisconnection.protocol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _testDataForward

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import protocol [as 别名]
    def _testDataForward(self, data, method="GET", body=""):
        """
        Build a fake proxy connection, and send C{data} over it, checking that
        it's forwarded to the originating request.
        """
        # Connect everything
        clientTransport = StringTransportWithDisconnection()
        serverTransport = StringTransportWithDisconnection()
        channel = DummyChannel(serverTransport)
        parent = DummyParent(channel)
        serverTransport.protocol = channel

        client = ProxyClient(method, '/foo', 'HTTP/1.0',
                             {"accept": "text/html"}, body, parent)
        clientTransport.protocol = client
        client.makeConnection(clientTransport)

        # Check data sent
        self.assertEquals(clientTransport.value(),
            "%s /foo HTTP/1.0\r\n"
            "connection: close\r\n"
            "accept: text/html\r\n\r\n%s" % (method, body))

        # Fake an answer
        client.dataReceived(data)

        # Check that the data has been forwarded
        self.assertEquals(serverTransport.value(), data)

        clientTransport.loseConnection()
        self.assertIsInstance(channel.lostReason, ConnectionDone)
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:33,代码来源:test_proxy.py

示例2: test_renderIProtocol

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import protocol [as 别名]
    def test_renderIProtocol(self):
        """
        If the protocol returned by C{lookupProtocol} isn't a
        C{WebSocketsProtocol}, L{WebSocketsResource} wraps it automatically
        with L{WebSocketsProtocolWrapper}.
        """

        def lookupProtocol(names, otherRequest):
            return AccumulatingProtocol(), None

        self.resource = WebSocketsResource(lookupProtocol)

        request = DummyRequest("/")
        request.requestHeaders = Headers()
        transport = StringTransportWithDisconnection()
        transport.protocol = Protocol()
        request.transport = transport
        request.headers.update({
            "upgrade": "Websocket",
            "connection": "Upgrade",
            "sec-websocket-key": "secure",
            "sec-websocket-version": "13"})
        result = self.resource.render(request)
        self.assertEqual(NOT_DONE_YET, result)
        self.assertIsInstance(transport.protocol, WebSocketsProtocolWrapper)
        self.assertIsInstance(transport.protocol.wrappedProtocol,
                              AccumulatingProtocol)
开发者ID:codecats,项目名称:kitty,代码行数:29,代码来源:test_websockets.py

示例3: test_renderSecureRequest

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import protocol [as 别名]
 def test_renderSecureRequest(self):
     """
     When the rendered request is over HTTPS, L{WebSocketsResource} wraps
     the protocol of the C{TLSMemoryBIOProtocol} instance.
     """
     request = DummyRequest("/")
     request.requestHeaders = Headers()
     transport = StringTransportWithDisconnection()
     secureProtocol = TLSMemoryBIOProtocol(Factory(), Protocol())
     transport.protocol = secureProtocol
     request.transport = transport
     request.headers.update({
         "upgrade": "Websocket",
         "connection": "Upgrade",
         "sec-websocket-key": "secure",
         "sec-websocket-version": "13"})
     result = self.resource.render(request)
     self.assertEqual(NOT_DONE_YET, result)
     self.assertEqual(
         {"connection": "Upgrade",
          "upgrade": "WebSocket",
          "sec-websocket-accept": "oYBv54i42V5dw6KnZqOFroecUTc="},
         request.outgoingHeaders)
     self.assertEqual([""], request.written)
     self.assertEqual(101, request.responseCode)
     self.assertIdentical(None, request.transport)
     self.assertIsInstance(
         transport.protocol.wrappedProtocol, WebSocketsProtocol)
     self.assertIsInstance(
         transport.protocol.wrappedProtocol._receiver,
         SavingEchoReceiver)
开发者ID:codecats,项目名称:kitty,代码行数:33,代码来源:test_websockets.py

示例4: test_renderProtocol

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import protocol [as 别名]
    def test_renderProtocol(self):
        """
        If protocols are specified via the C{Sec-WebSocket-Protocol} header,
        L{WebSocketsResource} passes them to its C{lookupProtocol} argument,
        which can decide which protocol to return, and which is accepted.
        """

        def lookupProtocol(names, otherRequest):
            self.assertEqual(["foo", "bar"], names)
            self.assertIdentical(request, otherRequest)
            return self.echoProtocol, "bar"

        self.resource = WebSocketsResource(lookupProtocol)

        request = DummyRequest("/")
        request.requestHeaders = Headers(
            {"sec-websocket-protocol": ["foo", "bar"]})
        transport = StringTransportWithDisconnection()
        transport.protocol = Protocol()
        request.transport = transport
        request.headers.update({
            "upgrade": "Websocket",
            "connection": "Upgrade",
            "sec-websocket-key": "secure",
            "sec-websocket-version": "13"})
        result = self.resource.render(request)
        self.assertEqual(NOT_DONE_YET, result)
        self.assertEqual(
            {"connection": "Upgrade",
             "upgrade": "WebSocket",
             "sec-websocket-protocol": "bar",
             "sec-websocket-accept": "oYBv54i42V5dw6KnZqOFroecUTc="},
            request.outgoingHeaders)
        self.assertEqual([""], request.written)
        self.assertEqual(101, request.responseCode)
开发者ID:codecats,项目名称:kitty,代码行数:37,代码来源:test_websockets.py

示例5: test_render

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import protocol [as 别名]
 def test_render(self):
     """
     When rendering a request, L{WebSocketsResource} uses the
     C{Sec-WebSocket-Key} header to generate a C{Sec-WebSocket-Accept}
     value. It creates a L{WebSocketsProtocol} instance connected to the
     protocol provided by the user factory.
     """
     request = DummyRequest("/")
     request.requestHeaders = Headers()
     transport = StringTransportWithDisconnection()
     transport.protocol = Protocol()
     request.transport = transport
     request.headers.update({
         "upgrade": "Websocket",
         "connection": "Upgrade",
         "sec-websocket-key": "secure",
         "sec-websocket-version": "13"})
     result = self.resource.render(request)
     self.assertEqual(NOT_DONE_YET, result)
     self.assertEqual(
         {"connection": "Upgrade",
          "upgrade": "WebSocket",
          "sec-websocket-accept": "oYBv54i42V5dw6KnZqOFroecUTc="},
         request.outgoingHeaders)
     self.assertEqual([""], request.written)
     self.assertEqual(101, request.responseCode)
     self.assertIdentical(None, request.transport)
     self.assertIsInstance(transport.protocol._receiver,
                           SavingEchoReceiver)
开发者ID:codecats,项目名称:kitty,代码行数:31,代码来源:test_websockets.py

示例6: test_writeLimit

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import protocol [as 别名]
    def test_writeLimit(self):
        """
        Check the writeLimit parameter: write data, and check for the pause
        status.
        """
        server = Server()
        tServer = TestableThrottlingFactory(task.Clock(), server, writeLimit=10)
        port = tServer.buildProtocol(address.IPv4Address('TCP', '127.0.0.1', 0))
        tr = StringTransportWithDisconnection()
        tr.protocol = port
        port.makeConnection(tr)
        port.producer = port.wrappedProtocol

        port.dataReceived("0123456789")
        port.dataReceived("abcdefghij")
        self.assertEqual(tr.value(), "0123456789abcdefghij")
        self.assertEqual(tServer.writtenThisSecond, 20)
        self.assertFalse(port.wrappedProtocol.paused)

        # at this point server should've written 20 bytes, 10 bytes
        # above the limit so writing should be paused around 1 second
        # from 'now', and resumed a second after that
        tServer.clock.advance(1.05)
        self.assertEqual(tServer.writtenThisSecond, 0)
        self.assertTrue(port.wrappedProtocol.paused)

        tServer.clock.advance(1.05)
        self.assertEqual(tServer.writtenThisSecond, 0)
        self.assertFalse(port.wrappedProtocol.paused)
开发者ID:BillAndersan,项目名称:twisted,代码行数:31,代码来源:test_policies.py

示例7: test_connectToNode

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import protocol [as 别名]
 def test_connectToNode(self):
     """
     L{OneShotPortMapperFactory.connectToNode} should return a L{Deferred}
     that will be called back with the instance of the protocol connected
     to the erlang node.
     """
     clientFactory = DummyClientFactory()
     self.factory.nodeFactoryClass = lambda a, b, c: clientFactory
     d = self.factory.connectToNode("[email protected]")
     transport = StringTransportWithDisconnection()
     proto = self.factory.buildProtocol(("127.0.01", 4369))
     proto.makeConnection(transport)
     transport.protocol = proto
     self.assertEqual(transport.value(), "\x00\x04zegg")
     self.assertEqual(
         self.factory.connect, [("127.0.0.1", 4369, self.factory)])
     proto.dataReceived(
         "w\x00\x00\x09M\x01\x00\x05\x00\x05\x00\x03bar\x00")
     clientProto = object()
     clientFactory._connectDeferred.callback(clientProto)
     self.assertEqual(
         self.factory.connect,
         [("127.0.0.1", 4369, self.factory),
          ("127.0.0.1", 9, clientFactory)])
     return d.addCallback(self.assertIdentical, clientProto)
开发者ID:gbour,项目名称:twotp,代码行数:27,代码来源:test_epmd.py

示例8: test_rawsocket_with_factory

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import protocol [as 别名]
    def test_rawsocket_with_factory(self):
        """
        Speaking RawSocket when the connection is made will make UniSocket
        create a new RawSocket protocol and send the data to it.
        """
        t = StringTransport()

        class MyFakeRawSocket(Protocol):
            """
            A fake RawSocket factory which just echos data back.
            """
            def dataReceived(self, data):
                self.transport.write(data)

        fake_rawsocket = Factory.forProtocol(MyFakeRawSocket)
        f = UniSocketServerFactory(rawsocket_factory=fake_rawsocket)
        p = f.buildProtocol(None)

        p.makeConnection(t)
        t.protocol = p

        self.assertTrue(t.connected)
        p.dataReceived(b'\x7F0000000')
        p.dataReceived(b'moredata')

        self.assertTrue(t.connected)
        self.assertEqual(t.value(), b'\x7F0000000moredata')
开发者ID:schoonc,项目名称:crossbar,代码行数:29,代码来源:test_unisocket.py

示例9: test_websocket_with_map

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import protocol [as 别名]
    def test_websocket_with_map(self):
        """
        Speaking WebSocket when the connection is made will make UniSocket
        create a new WebSocket protocol and send the data to it.
        """
        t = StringTransport()

        class MyFakeWebSocket(Protocol):
            """
            A fake WebSocket factory which just echos data back.
            """
            def dataReceived(self, data):
                self.transport.write(data)

        fake_websocket = Factory.forProtocol(MyFakeWebSocket)
        websocket_map = OrderedDict({u"baz": None})
        websocket_map["ws"] = fake_websocket

        f = UniSocketServerFactory(websocket_factory_map=websocket_map)
        p = f.buildProtocol(None)

        p.makeConnection(t)
        t.protocol = p

        self.assertTrue(t.connected)
        p.dataReceived(b'GET /ws HTTP/1.1\r\nConnection: close\r\n\r\n')

        self.assertTrue(t.connected)
        self.assertEqual(t.value(),
                         b'GET /ws HTTP/1.1\r\nConnection: close\r\n\r\n')
开发者ID:schoonc,项目名称:crossbar,代码行数:32,代码来源:test_unisocket.py

示例10: test_web_with_factory

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import protocol [as 别名]
    def test_web_with_factory(self):
        """
        Speaking HTTP will pass it down to the HTTP factory.
        """
        t = StringTransport()

        class MyResource(Resource):
            isLeaf = True

            def render_GET(self, request):
                return b"hi!"

        r = MyResource()
        s = Site(r)

        f = UniSocketServerFactory(web_factory=s)
        p = f.buildProtocol(None)

        p.makeConnection(t)
        t.protocol = p

        self.assertTrue(t.connected)
        p.dataReceived(b'GET / HTTP/1.1\r\nConnection: close\r\n\r\n')
        self.assertFalse(t.connected)

        self.assertIn(b"hi!", t.value())
开发者ID:schoonc,项目名称:crossbar,代码行数:28,代码来源:test_unisocket.py

示例11: test_getNodeConnection

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import protocol [as 别名]
    def test_getNodeConnection(self):
        """
        L{Process._getNodeConnection}, if no connection is established, as a
        connection to a L{OneShotPortMapperFactory}. Once it gets a connection
        it sets the calls handler to the client factory to the process handler.
        """
        d = self.process._getNodeConnection("[email protected]")

        epmd = self.process.oneShotEpmds["spam"]
        transport = StringTransportWithDisconnection()
        proto = epmd.buildProtocol(("127.0.01", 4369))
        proto.makeConnection(transport)
        transport.protocol = proto
        self.assertEqual(transport.value(), "\x00\x04zegg")
        self.assertEqual(epmd.connect, [("spam", 4369, epmd)])
        proto.dataReceived(
            "w\x00\x00\x09M\x01\x00\x05\x00\x05\x00\x03bar\x00")

        [factory] = epmd.factories
        self.assertEqual(
            epmd.factoriesArgs,
            [("[email protected]", "test_cookie", epmd.onConnectionLost)])

        clientProto = TestableNodeProtocol()
        clientProto.factory = factory
        factory._connectDeferred.callback(clientProto)

        def check(proto):
            self.assertIdentical(proto, clientProto)
            self.assertIdentical(factory.handler, self.process.handler)

        return d.addCallback(check)
开发者ID:springstar,项目名称:twotp,代码行数:34,代码来源:test_node.py

示例12: test_thingsGetLogged

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import protocol [as 别名]
    def test_thingsGetLogged(self):
        """
        Check the output produced by L{policies.TrafficLoggingFactory}.
        """
        wrappedFactory = Server()
        wrappedFactory.protocol = WriteSequenceEchoProtocol
        t = StringTransportWithDisconnection()
        f = TestLoggingFactory(wrappedFactory, 'test')
        p = f.buildProtocol(('1.2.3.4', 5678))
        t.protocol = p
        p.makeConnection(t)

        v = f.openFile.getvalue()
        self.failUnless('*' in v, "* not found in %r" % (v,))
        self.failIf(t.value())

        p.dataReceived('here are some bytes')

        v = f.openFile.getvalue()
        self.assertIn("C 1: 'here are some bytes'", v)
        self.assertIn("S 1: 'here are some bytes'", v)
        self.assertEqual(t.value(), 'here are some bytes')

        t.clear()
        p.dataReceived('prepare for vector! to the extreme')
        v = f.openFile.getvalue()
        self.assertIn("SV 1: ['prepare for vector! to the extreme']", v)
        self.assertEqual(t.value(), 'prepare for vector! to the extreme')

        p.loseConnection()

        v = f.openFile.getvalue()
        self.assertIn('ConnectionDone', v)
开发者ID:BillAndersan,项目名称:twisted,代码行数:35,代码来源:test_policies.py

示例13: connect_transport

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import protocol [as 别名]
def connect_transport(protocol, factory=None):
    """ Connect a StringTransport to a client protocol. """
    if factory is None:
        factory = ClientFactory()
    transport = StringTransportWithDisconnection()
    protocol.makeConnection(transport)
    transport.protocol = protocol
    protocol.factory = factory
    return transport
开发者ID:praekelt,项目名称:vumi-freeswitch-esl,代码行数:11,代码来源:test_client.py

示例14: connect

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import protocol [as 别名]
 def connect(self, protocolFactory):
     string_transport = StringTransportWithDisconnection()
     protocol = protocolFactory.buildProtocol(None)
     protocol.makeConnection(string_transport)
     string_transport.protocol = protocol
     self.connect_callback(protocol)
     d = Deferred()
     d.callback(protocol)
     return d
开发者ID:areski,项目名称:vumi,代码行数:11,代码来源:test_truteq.py

示例15: gen_prot

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import protocol [as 别名]
     def gen_prot(self, app):
        from spyne.server.twisted.msgpack import TwistedMessagePackProtocol
        from twisted.test.proto_helpers import StringTransportWithDisconnection

        prot = TwistedMessagePackProtocol(app)
        transport = StringTransportWithDisconnection()
        prot.makeConnection(transport)
        transport.protocol = prot

        return prot
开发者ID:codenginebd,项目名称:spyne,代码行数:12,代码来源:test_msgpack.py


注:本文中的twisted.test.proto_helpers.StringTransportWithDisconnection.protocol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。