本文整理汇总了Python中hyperframe.frame.DataFrame.serialize方法的典型用法代码示例。如果您正苦于以下问题:Python DataFrame.serialize方法的具体用法?Python DataFrame.serialize怎么用?Python DataFrame.serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hyperframe.frame.DataFrame
的用法示例。
在下文中一共展示了DataFrame.serialize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: socket_handler
# 需要导入模块: from hyperframe.frame import DataFrame [as 别名]
# 或者: from hyperframe.frame.DataFrame import serialize [as 别名]
def socket_handler(listener):
sock = listener.accept()[0]
# We get two messages for the connection open and then a HEADERS
# frame.
receive_preamble(sock)
sock.recv(65535)
# Now, send the headers for the response. This response has a body.
f = build_headers_frame([(':status', '200')])
f.stream_id = 1
sock.send(f.serialize())
# Send the first two chunks.
f = DataFrame(1)
f.data = b'hello'
sock.sendall(f.serialize())
f = DataFrame(1)
f.data = b'there'
sock.sendall(f.serialize())
# Now, delay a bit. We want to wait a half a second before we send
# the next frame.
wait_event.wait(5)
time.sleep(0.5)
f = DataFrame(1)
f.data = b'world'
f.flags.add('END_STREAM')
sock.sendall(f.serialize())
# Wait for the message from the main thread.
recv_event.set()
sock.close()
示例2: test_stream_window_increments_appropriately
# 需要导入模块: from hyperframe.frame import DataFrame [as 别名]
# 或者: from hyperframe.frame.DataFrame import serialize [as 别名]
def test_stream_window_increments_appropriately(self, frame_buffer):
e = Encoder()
h = HeadersFrame(1)
h.data = e.encode([(':status', 200), ('content-type', 'foo/bar')])
h.flags = set(['END_HEADERS'])
d = DataFrame(1)
d.data = b'hi there sir'
d2 = DataFrame(1)
d2.data = b'hi there sir again'
sock = DummySocket()
sock.buffer = BytesIO(h.serialize() + d.serialize() + d2.serialize())
c = HTTP20Connection('www.google.com')
c._sock = sock
c.request('GET', '/')
c.streams[1]._in_window_manager.window_size = 1000
c.streams[1]._in_window_manager.initial_window_size = 1000
resp = c.get_response()
resp.read(len(b'hi there sir'))
resp.read(len(b'hi there sir again'))
frame_buffer.add_data(b''.join(sock.queue))
queue = list(frame_buffer)
assert len(queue) == 3 # one headers frame, two window update frames.
assert isinstance(queue[1], WindowUpdateFrame)
assert queue[1].window_increment == len(b'hi there sir')
assert isinstance(queue[2], WindowUpdateFrame)
assert queue[2].window_increment == len(b'hi there sir again')
示例3: test_body_length_behaves_correctly
# 需要导入模块: from hyperframe.frame import DataFrame [as 别名]
# 或者: from hyperframe.frame.DataFrame import serialize [as 别名]
def test_body_length_behaves_correctly(self):
f = DataFrame(1)
f.data = b'\x01' * 300
# Initially the body length is zero. For now this is incidental, but
# I'm going to test it to ensure that the behaviour is codified. We
# should change this test if we change that.
assert f.body_len == 0
f.serialize()
assert f.body_len == 300
示例4: test_data_frame_serializes_properly
# 需要导入模块: from hyperframe.frame import DataFrame [as 别名]
# 或者: from hyperframe.frame.DataFrame import serialize [as 别名]
def test_data_frame_serializes_properly(self):
f = DataFrame(1)
f.flags = set(['END_STREAM'])
f.data = b'testdata'
s = f.serialize()
assert s == self.payload
示例5: test_data_frame_with_padding_serializes_properly
# 需要导入模块: from hyperframe.frame import DataFrame [as 别名]
# 或者: from hyperframe.frame.DataFrame import serialize [as 别名]
def test_data_frame_with_padding_serializes_properly(self):
f = DataFrame(1)
f.flags = set(['END_STREAM', 'PADDED'])
f.data = b'testdata'
f.pad_length = 10
s = f.serialize()
assert s == self.payload_with_padding
示例6: test_data_frame_with_no_length_parses
# 需要导入模块: from hyperframe.frame import DataFrame [as 别名]
# 或者: from hyperframe.frame.DataFrame import serialize [as 别名]
def test_data_frame_with_no_length_parses(self):
# Fixes issue with empty data frames raising InvalidPaddingError.
f = DataFrame(1)
f.data = b''
data = f.serialize()
new_frame = decode_frame(data)
assert new_frame.data == b''
示例7: test_long_data_frame
# 需要导入模块: from hyperframe.frame import DataFrame [as 别名]
# 或者: from hyperframe.frame.DataFrame import serialize [as 别名]
def test_long_data_frame(self):
f = DataFrame(1)
# Use more than 256 bytes of data to force setting higher bits.
f.data = b'\x01' * 300
data = f.serialize()
# The top three bytes should be numerically equal to 300. That means
# they should read 00 01 2C.
# The weird double index trick is to ensure this test behaves equally
# on Python 2 and Python 3.
assert data[0] == b'\x00'[0]
assert data[1] == b'\x01'[0]
assert data[2] == b'\x2C'[0]
示例8: write_raw_data_frame
# 需要导入模块: from hyperframe.frame import DataFrame [as 别名]
# 或者: from hyperframe.frame.DataFrame import serialize [as 别名]
def write_raw_data_frame(self, data, stream_id=None, end_stream=False):
"""
Ignores the statemachine of the stream and sends a DATA frame regardless.
Unlike `write_data`, this does not check to see if a stream is in the correct state to have DATA frames
sent through to it. It will build a DATA frame and send it without using the H2 Connection object. It will
not perform any flow control checks.
:param data: The data to be sent in the frame
:param stream_id: Id of stream to send frame on. Will use the request stream ID if None
:param end_stream: Set to True to add END_STREAM flag to frame
"""
if not stream_id:
stream_id = self.request.h2_stream_id
frame = DataFrame(stream_id, data=data)
if end_stream:
self.stream_ended = True
frame.flags.add('END_STREAM')
data = frame.serialize()
self.write_raw(data)