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


Python Frame.build方法代码示例

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


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

示例1: test_63_bit_length

# 需要导入模块: from ws4py.framing import Frame [as 别名]
# 或者: from ws4py.framing.Frame import build [as 别名]
    def test_63_bit_length(self):
        f = Frame(opcode=OPCODE_TEXT, body=b"*" * 65536, fin=1)
        self.assertEqual(len(f.build()), 65546)

        mask = os.urandom(4)
        f = Frame(opcode=OPCODE_TEXT, body=b"*" * 65536, masking_key=mask, fin=1)
        self.assertEqual(len(f.build()), 65550)
开发者ID:lovejavaee,项目名称:WebSocket-for-Python,代码行数:9,代码来源:test_frame.py

示例2: test_16_bit_length

# 需要导入模块: from ws4py.framing import Frame [as 别名]
# 或者: from ws4py.framing.Frame import build [as 别名]
    def test_16_bit_length(self):
        f = Frame(opcode=OPCODE_TEXT, body=b"*" * 126, fin=1)
        self.assertEqual(len(f.build()), 130)

        f = Frame(opcode=OPCODE_TEXT, body=b"*" * 65535, fin=1)
        self.assertEqual(len(f.build()), 65539)

        mask = os.urandom(4)
        f = Frame(opcode=OPCODE_TEXT, body=b"*" * 126, masking_key=mask, fin=1)
        self.assertEqual(len(f.build()), 134)

        f = Frame(opcode=OPCODE_TEXT, body=b"*" * 65535, masking_key=mask, fin=1)
        self.assertEqual(len(f.build()), 65543)
开发者ID:lovejavaee,项目名称:WebSocket-for-Python,代码行数:15,代码来源:test_frame.py

示例3: test_7_bit_length

# 需要导入模块: from ws4py.framing import Frame [as 别名]
# 或者: from ws4py.framing.Frame import build [as 别名]
    def test_7_bit_length(self):
        f = Frame(opcode=OPCODE_TEXT, body=b"", fin=1)
        self.assertEqual(len(f.build()), 2)

        f = Frame(opcode=OPCODE_TEXT, body=b"*" * 125, fin=1)
        self.assertEqual(len(f.build()), 127)

        mask = os.urandom(4)
        f = Frame(opcode=OPCODE_TEXT, body=b"", masking_key=mask, fin=1)
        self.assertEqual(len(f.build()), 6)

        f = Frame(opcode=OPCODE_TEXT, body=b"*" * 125, masking_key=mask, fin=1)
        self.assertEqual(len(f.build()), 131)
开发者ID:lovejavaee,项目名称:WebSocket-for-Python,代码行数:15,代码来源:test_frame.py

示例4: test_masking

# 需要导入模块: from ws4py.framing import Frame [as 别名]
# 或者: from ws4py.framing.Frame import build [as 别名]
    def test_masking(self):
        mask = "7\xfa!="
        f = Frame(opcode=OPCODE_TEXT,
                  body='Hello', masking_key=mask, fin=1)

        spec_says = '\x81\x857\xfa!=\x7f\x9fMQX'
        self.assertEqual(f.build(), spec_says)
开发者ID:Queatz,项目名称:WebSocket-for-Python,代码行数:9,代码来源:test_frame.py

示例5: test_opcodes

# 需要导入模块: from ws4py.framing import Frame [as 别名]
# 或者: from ws4py.framing.Frame import build [as 别名]
    def test_opcodes(self):
        for opcode in [OPCODE_CONTINUATION, OPCODE_TEXT, OPCODE_BINARY, OPCODE_CLOSE, OPCODE_PING, OPCODE_PONG]:
            f = Frame(opcode=opcode, body=b"", fin=1)
            byte = ord(f.build()[0])
            self.assertTrue(byte & opcode == opcode)

        f = Frame(opcode=0x3, body=b"", fin=1)
        self.assertRaises(ValueError, f.build)
开发者ID:lovejavaee,项目名称:WebSocket-for-Python,代码行数:10,代码来源:test_frame.py

示例6: test_masking

# 需要导入模块: from ws4py.framing import Frame [as 别名]
# 或者: from ws4py.framing.Frame import build [as 别名]
    def test_masking(self):
        if py3k: mask = b"7\xfa!="
        else: mask = "7\xfa!="
        f = Frame(opcode=OPCODE_TEXT,
                  body=enc('Hello'),
                  masking_key=mask, fin=1)

        if py3k: spec_says = b'\x81\x857\xfa!=\x7f\x9fMQX'
        else: spec_says = '\x81\x857\xfa!=\x7f\x9fMQX'
        self.assertEqual(f.build(), spec_says)
开发者ID:EliAndrewC,项目名称:WebSocket-for-Python,代码行数:12,代码来源:test_frame.py

示例7: received_message

# 需要导入模块: from ws4py.framing import Frame [as 别名]
# 或者: from ws4py.framing.Frame import build [as 别名]
 def received_message(self, m):
     # Assuming type of arraybuffer
     xx = N.fromstring(m.data, N.int16, count=5)
     # xx = N.fromstring(m.data, N.float32, count=4)
     print xx
     xx = xx*2;
     f = Frame(OPCODE_BINARY, xx.tostring(), fin=1)
     b = f.build()
     yy = BinaryMessage(b)
     for conn in SUBSCRIBERS:
     	conn.send(yy)
开发者ID:kpotter,项目名称:SamVis,代码行数:13,代码来源:simple_ws_server.py

示例8: test_protocol_exception_from_frame_parsing

# 需要导入模块: from ws4py.framing import Frame [as 别名]
# 或者: from ws4py.framing.Frame import build [as 别名]
 def test_protocol_exception_from_frame_parsing(self):
     payload = struct.pack("!H", 1000) + b'hello'
     f = Frame(opcode=OPCODE_CLOSE, body=payload,
               fin=1, masking_key=os.urandom(4))
     f.rsv1 = 1
     f = f.build()
     s = Stream()
     self.assertEqual(len(s.errors), 0)
     self.assertEqual(s.closing, None)
     s.parser.send(f)
     self.assertEqual(s.closing, None)
     self.assertEqual(type(s.errors[0]), CloseControlMessage)
     self.assertEqual(s.errors[0].code, 1002)
开发者ID:17dakmue,项目名称:WebSocket-for-Python,代码行数:15,代码来源:test_stream.py

示例9: test_passing_encoded_string

# 需要导入模块: from ws4py.framing import Frame [as 别名]
# 或者: from ws4py.framing.Frame import build [as 别名]
 def test_passing_encoded_string(self):
     # once encoded the u'\xe9' character will be of length 2
     f = Frame(opcode=OPCODE_TEXT, body=u'\xe9trange'.encode('utf-8'), fin=1)
     self.assertEqual(len(f.build()), 10)
开发者ID:MeTrina,项目名称:WebSocket-for-Python,代码行数:6,代码来源:test_frame.py


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