本文整理汇总了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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)