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


Python StringTransportWithDisconnection.value方法代码示例

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


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

示例1: test_thingsGetLogged

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import value [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

示例2: _testDataForward

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import value [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

示例3: ProtocolTestCase

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import value [as 别名]
class ProtocolTestCase(unittest.TestCase):

    def setUp(self):
        self.proto = Redis()
        self.transport = StringTransportWithDisconnection()
        self.transport.protocol = self.proto
        self.proto.makeConnection(self.transport)

    def sendResponse(self, data):
        self.proto.dataReceived(data)

    def test_error_response(self):
        # pretending 'foo' is a set, so get is incorrect
        d = self.proto.get("foo")
        self.assertEquals(
            self.transport.value(),
            '*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n')
        msg = "Operation against a key holding the wrong kind of value"
        self.sendResponse("-%s\r\n" % msg)
        self.failUnlessFailure(d, ResponseError)

        def check_err(r):
            self.assertEquals(str(r), msg)
        return d

    @defer.inlineCallbacks
    def test_singleline_response(self):
        d = self.proto.ping()
        self.assertEquals(self.transport.value(), '*1\r\n$4\r\nPING\r\n')
        self.sendResponse("+PONG\r\n")
        r = yield d
        self.assertEquals(r, 'PONG')

    @defer.inlineCallbacks
    def test_bulk_response(self):
        d = self.proto.get("foo")
        self.assertEquals(
            self.transport.value(),
            '*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n')
        self.sendResponse("$3\r\nbar\r\n")
        r = yield d
        self.assertEquals(r, 'bar')

    @defer.inlineCallbacks
    def test_multibulk_response(self):
        d = self.proto.lrange("foo", 0, 1)
        expected = '*4\r\n$6\r\nLRANGE\r\n$3\r\nfoo\r\n$1\r\n0\r\n$1\r\n1\r\n'
        self.assertEquals(self.transport.value(), expected)
        self.sendResponse("*2\r\n$3\r\nbar\r\n$6\r\nlolwut\r\n")
        r = yield d
        self.assertEquals(r, ['bar', 'lolwut'])

    @defer.inlineCallbacks
    def test_integer_response(self):
        d = self.proto.dbsize()
        self.assertEquals(self.transport.value(), '*1\r\n$6\r\nDBSIZE\r\n')
        self.sendResponse(":1234\r\n")
        r = yield d
        self.assertEquals(r, 1234)
开发者ID:oubiwann-unsupported,项目名称:txRedis,代码行数:61,代码来源:test_protocol.py

示例4: Protocol

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import value [as 别名]
class Protocol(unittest.TestCase):

    def setUp(self):
        self.proto = Redis()
        self.transport = StringTransportWithDisconnection()
        self.transport.protocol = self.proto
        self.proto.makeConnection(self.transport)

    def sendResponse(self, data):
        self.proto.dataReceived(data)

    @defer.inlineCallbacks
    def test_error_response(self):
        # pretending 'foo' is a set, so get is incorrect
        d = self.proto.get("foo")
        self.assertEquals(self.transport.value(), "GET foo\r\n")
        msg = "Operation against a key holding the wrong kind of value"
        self.sendResponse("-%s\r\n" % msg)
        r = yield d
        self.assertEquals(str(r), msg)

    @defer.inlineCallbacks
    def test_singleline_response(self):
        d = self.proto.ping()
        self.assertEquals(self.transport.value(), "PING\r\n")
        self.sendResponse("+PONG\r\n")
        r = yield d
        self.assertEquals(r, 'PONG')

    @defer.inlineCallbacks
    def test_bulk_response(self):
        d = self.proto.get("foo")
        self.assertEquals(self.transport.value(), "GET foo\r\n")
        self.sendResponse("$3\r\nbar\r\n")
        r = yield d
        self.assertEquals(r, 'bar')

    @defer.inlineCallbacks
    def test_multibulk_response(self):
        d = self.proto.lrange("foo", 0, 1)
        self.assertEquals(self.transport.value(), "LRANGE foo 0 1\r\n")
        self.sendResponse("*2\r\n$3\r\nbar\r\n$6\r\nlolwut\r\n")
        r = yield d
        self.assertEquals(r, ['bar', 'lolwut'])

    @defer.inlineCallbacks
    def test_integer_response(self):
        d = self.proto.dbsize()
        self.assertEquals(self.transport.value(), "DBSIZE\r\n")
        self.sendResponse(":1234\r\n")
        r = yield d
        self.assertEquals(r, 1234)
开发者ID:djfroofy,项目名称:txRedis,代码行数:54,代码来源:test_redis.py

示例5: test_connectToNode

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import value [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

示例6: test_writeLimit

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import value [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_rawsocket_with_factory

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import value [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

示例8: test_websocket_with_map

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import value [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

示例9: test_web_with_factory

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import value [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

示例10: test_getNodeConnection

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import value [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

示例11: TestProtocol

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import value [as 别名]
class TestProtocol(common.TestCase):

    def setUp(self):
        self.transport = StringTransportWithDisconnection()
        self.protocol = httpclient.Protocol(self, owner=None)
        self.protocol.factory = MockFactory()
        self.protocol.makeConnection(self.transport)
        self.transport.protocol = self.protocol

        self.addCleanup(self._disconnect_protocol)

    @defer.inlineCallbacks
    def testSimpleRequest(self):
        self.assertTrue(self.protocol.factory.onConnectionMade_called)
        self.assertTrue(self.protocol.is_idle())

        d = self.protocol.request(http.Methods.GET, '/',
                                  headers={'accept': 'text/html'})
        self.assertEqual('GET / HTTP/1.1\r\n'
                         'Accept: text/html\r\n\r\n', self.transport.value())

        self.assertFalse(self.protocol.is_idle())

        self.protocol.dataReceived(
            self.protocol.delimiter.join([
                "HTTP/1.1 200 OK",
                "Content-Type: text/html",
                "Content-Length: 12",
                "",
                "This is body",
                ]))
        response = yield d
        self.assertIsInstance(response, httpclient.Response)
        self.assertEqual(200, response.status)
        self.assertEqual({'content-type': 'text/html',
                          'content-length': '12'}, response.headers)
        self.assertEqual('This is body', response.body)
        self.assertTrue(self.protocol.is_idle())

        self.assertTrue(self.protocol.factory.onConnectionReset_called)

    @defer.inlineCallbacks
    def testCancelledRequest(self):
        d = self.protocol.request(http.Methods.GET, '/',
                                  headers={'accept': 'text/html'})
        d.cancel()

        self.assertFalse(self.transport.connected)
        self.assertFailure(d, httpclient.RequestCancelled)
        f = yield d
        exp = ('GET to http://10.0.0.1:12345/ was cancelled '
               '0.(\d+)s after it was sent.')
        self.assertTrue(re.match(exp, str(f)), str(f))

    def _disconnect_protocol(self):
        if self.transport.connected:
            self.transport.loseConnection()
        self.assertTrue(self.protocol.factory.onConnectionLost_called)
开发者ID:f3at,项目名称:feat,代码行数:60,代码来源:test_web_httpclient.py

示例12: test_loseConnectionCodeAndReason

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import value [as 别名]
 def test_loseConnectionCodeAndReason(self):
     """
     L{WebSocketsTransport.loseConnection} accepts a code and a reason which
     are used to build the closing frame.
     """
     transport = StringTransportWithDisconnection()
     transport.protocol = Protocol()
     webSocketsTranport = WebSocketsTransport(transport)
     webSocketsTranport.loseConnection(STATUSES.GOING_AWAY, "Going away")
     self.assertEqual("\x88\x0c\x03\xe9Going away", transport.value())
开发者ID:codecats,项目名称:kitty,代码行数:12,代码来源:test_websockets.py

示例13: TestProtocol

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import value [as 别名]
class TestProtocol(TestCase):
    def setUp(self):
        self.protocol = ChatProtocol()
        self.transport = StringTransportWithDisconnection()
        self.protocol.factory = ChatProtocolFactory()
        self.protocol.makeConnection(self.transport)
        self.transport.protocol = self.protocol
        fl = os.open(self.protocol.factory.filename, os.O_CREAT |
                                                   os.O_RDWR)
                                                    
        os.write(fl, 'hey ho\n')
        os.close(fl)
    
    def split_commands(self):
        return self.transport.value().splitlines()
        
    def assertCommands(self, args):
        commands = self.split_commands()
        cmd_list = [parsingCommand(cmd) for cmd in commands]
        arg_list = [parsingCommand(arg) for arg in args]
        for (cmd, arg) in zip(cmd_list, arg_list):
            self.assertEquals(arg[1], cmd[1])
            if arg[2]:
                self.assertEquals(arg[2], cmd[2])
        
    def test_connect_command(self):
        self.protocol.lineReceived("CONNECT hey ho")
        self.assertCommands(['OK', 'SERVICE', 'NAMES'])
       
    def test_new_command_error_incorrect_data(self):
        self.protocol.lineReceived("NEW gahhahjjkjsfkkfkk ho")
        self.assertCommands(["ERROR '%s'" % 
                             err_text['err_incorrect_data']])
       
    
    def test_new_command_error_usr_exist(self):
        self.protocol.lineReceived("NEW hey ho")
        self.assertCommands(["ERROR '%s'" % 
                              err_text['err_user_exist']])
    
    def test_msg_command(self):
        self.protocol.lineReceived("CONNECT hey ho")
        self.protocol.lineReceived("!hey MSG * 'message'")
        
        self.assertCommands(['OK', 'SERVICE', 'NAMES', 'MSG'])
        
    def test_nick_command(self):
        self.protocol.lineReceived("CONNECT hey ho")
        self.protocol.lineReceived("!hey NICK newnick")

        self.assertCommands(['OK', 'SERVICE', 'NAMES']*2)
    
    def tearDown(self):
        self.protocol.transport.loseConnection()
开发者ID:vincentshi,项目名称:python_chat,代码行数:56,代码来源:test_basecmd.py

示例14: test_connection

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import value [as 别名]
 def test_connection(self):
     """
     On connection, the EPMD client should send an ALIVE2 request.
     """
     self.factory.nodePortNumber = 1234
     transport = StringTransportWithDisconnection()
     proto = self.factory.buildProtocol(("127.0.01", 4369))
     proto.makeConnection(transport)
     transport.protocol = proto
     self.assertEquals(transport.value(),
         "\x00\x10x\x04\xd2H\x00\x00\x05\x00\x05\x00\x03foo\x00\x00")
开发者ID:cybergrind,项目名称:twotp,代码行数:13,代码来源:test_epmd.py

示例15: test_loseConnection

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import value [as 别名]
 def test_loseConnection(self):
     """
     L{WebSocketsTransport.loseConnection} sends a close frame and closes
     the transport afterwards.
     """
     transport = StringTransportWithDisconnection()
     transport.protocol = Protocol()
     webSocketsTranport = WebSocketsTransport(transport)
     webSocketsTranport.loseConnection()
     self.assertFalse(transport.connected)
     self.assertEqual("\x88\x02\x03\xe8", transport.value())
     # We can call loseConnection again without side effects
     webSocketsTranport.loseConnection()
开发者ID:codecats,项目名称:kitty,代码行数:15,代码来源:test_websockets.py


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