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


Python StringTransportWithDisconnection.getPeer方法代码示例

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


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

示例1: WebSocketsProtocolWrapperTest

# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import getPeer [as 别名]
class WebSocketsProtocolWrapperTest(TestCase):
    """
    Tests for L{WebSocketsProtocolWrapper}.
    """

    def setUp(self):
        self.accumulatingProtocol = AccumulatingProtocol()
        self.protocol = WebSocketsProtocolWrapper(self.accumulatingProtocol)
        self.transport = StringTransportWithDisconnection()
        self.protocol.makeConnection(self.transport)
        self.transport.protocol = self.protocol


    def test_dataReceived(self):
        """
        L{WebSocketsProtocolWrapper.dataReceived} forwards frame content to the
        underlying protocol.
        """
        self.protocol.dataReceived(
            _makeFrame("Hello", CONTROLS.TEXT, True, mask="abcd"))
        self.assertEqual("Hello", self.accumulatingProtocol.data)


    def test_controlFrames(self):
        """
        L{WebSocketsProtocolWrapper} doesn't forward data from control frames
        to the underlying protocol.
        """
        self.protocol.dataReceived(
            _makeFrame("Hello", CONTROLS.PING, True, mask="abcd"))
        self.protocol.dataReceived(
            _makeFrame("Hello", CONTROLS.PONG, True, mask="abcd"))
        self.protocol.dataReceived(
            _makeFrame("", CONTROLS.CLOSE, True, mask="abcd"))
        self.assertEqual("", self.accumulatingProtocol.data)


    def test_loseConnection(self):
        """
        L{WebSocketsProtocolWrapper.loseConnection} sends a close frame and
        disconnects the transport.
        """
        self.protocol.loseConnection()
        self.assertFalse(self.transport.connected)
        self.assertEqual("\x88\x02\x03\xe8", self.transport.value())


    def test_write(self):
        """
        L{WebSocketsProtocolWrapper.write} creates and writes a frame from the
        payload passed.
        """
        self.accumulatingProtocol.transport.write("Hello")
        self.assertEqual("\x81\x05Hello", self.transport.value())


    def test_writeSequence(self):
        """
        L{WebSocketsProtocolWrapper.writeSequence} writes a frame for every
        chunk passed.
        """
        self.accumulatingProtocol.transport.writeSequence(["Hello", "World"])
        self.assertEqual("\x81\x05Hello\x81\x05World", self.transport.value())


    def test_getHost(self):
        """
        L{WebSocketsProtocolWrapper.getHost} returns the transport C{getHost}.
        """
        self.assertEqual(self.transport.getHost(),
                         self.accumulatingProtocol.transport.getHost())


    def test_getPeer(self):
        """
        L{WebSocketsProtocolWrapper.getPeer} returns the transport C{getPeer}.
        """
        self.assertEqual(self.transport.getPeer(),
                         self.accumulatingProtocol.transport.getPeer())


    def test_connectionLost(self):
        """
        L{WebSocketsProtocolWrapper.connectionLost} forwards the connection
        lost call to the underlying protocol.
        """
        self.transport.loseConnection()
        self.assertTrue(self.accumulatingProtocol.closed)
开发者ID:codecats,项目名称:kitty,代码行数:90,代码来源:test_websockets.py


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