當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。