• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python proto_helpers.StringTransportWithDisconnection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_renderProtocol

    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,代码行数:35,代码来源:test_websockets.py


示例2: CommandFailureTests

class CommandFailureTests(CommandMixin, TestCase):
    """
    Tests for correct failure of commands on a disconnected
    L{MemCacheProtocol}.
    """

    def setUp(self):
        """
        Create a disconnected memcache client, using a deterministic clock.
        """
        self.proto = MemCacheProtocol()
        self.clock = Clock()
        self.proto.callLater = self.clock.callLater
        self.transport = StringTransportWithDisconnection()
        self.transport.protocol = self.proto
        self.proto.makeConnection(self.transport)
        self.transport.loseConnection()


    def _test(self, d, send, recv, result):
        """
        Implementation of C{_test} which checks that the command fails with
        C{RuntimeError} because the transport is disconnected. All the
        parameters except C{d} are ignored.
        """
        return self.assertFailure(d, RuntimeError)
开发者ID:AndyPanda95,项目名称:python-for-android,代码行数:26,代码来源:test_memcache.py


示例3: test_render

 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,代码行数:29,代码来源:test_websockets.py


示例4: test_connectToNode

 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,代码行数:25,代码来源:test_epmd.py


示例5: test_getNodeConnection

    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,代码行数:32,代码来源:test_node.py


示例6: test_writeLimit

    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,代码行数:29,代码来源:test_policies.py


示例7: test_renderSecureRequest

 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,代码行数:31,代码来源:test_websockets.py


示例8: test_renderIProtocol

    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,代码行数:27,代码来源:test_websockets.py


示例9: ProtocolTestCase

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,代码行数:59,代码来源:test_protocol.py


示例10: TestProtocol

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,代码行数:58,代码来源:test_web_httpclient.py


示例11: connect

 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,代码行数:9,代码来源:test_truteq.py


示例12: connect_transport

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,代码行数:9,代码来源:test_client.py


示例13: test_loseConnectionCodeAndReason

 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,代码行数:10,代码来源:test_websockets.py


示例14: gen_prot

     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,代码行数:10,代码来源:test_msgpack.py


示例15: test_connection

 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,代码行数:11,代码来源:test_epmd.py


示例16: test_invalidHeaderDisconnects

 def test_invalidHeaderDisconnects(self):
     """
     Test if invalid headers result in connectionLost events.
     """
     factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol))
     proto = factory.buildProtocol(address.IPv6Address("TCP", b"::1", 8080))
     transport = StringTransportWithDisconnection()
     transport.protocol = proto
     proto.makeConnection(transport)
     proto.dataReceived(b"\x00" + self.IPV4HEADER[1:])
     self.assertFalse(transport.connected)
开发者ID:JOLP,项目名称:SharingCode,代码行数:11,代码来源:test_wrapper.py


示例17: connectProxy

    def connectProxy(self, proxyClient):
        """
        Connect a proxy client to a L{StringTransportWithDisconnection}.

        @param proxyClient: A L{ProxyClient}.
        @return: The L{StringTransportWithDisconnection}.
        """
        clientTransport = StringTransportWithDisconnection()
        clientTransport.protocol = proxyClient
        proxyClient.makeConnection(clientTransport)
        return clientTransport
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:11,代码来源:test_proxy.py


示例18: makeTestConnections

def makeTestConnections(client):
    client.factories = []
    transports = []
    for addr in client.hosts:
        factory = MemCacheClientFactory()
        client.factories.append(factory)
        proto = factory.buildProtocol(addr, timeOut=None)
        transport = StringTransportWithDisconnection()
        transport.protocol = proto
        proto.makeConnection(transport)
        transports.append(transport)
    return transports
开发者ID:alberist,项目名称:txyam,代码行数:12,代码来源:utils.py


示例19: Protocol

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,代码行数:52,代码来源:test_redis.py


示例20: test_loseConnection

 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,代码行数:13,代码来源:test_websockets.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test_process.MockOS类代码示例发布时间:2022-05-27
下一篇:
Python proto_helpers.StringTransport类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap