本文整理汇总了Python中hyper.http20.stream.Stream._recv_cb方法的典型用法代码示例。如果您正苦于以下问题:Python Stream._recv_cb方法的具体用法?Python Stream._recv_cb怎么用?Python Stream._recv_cb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hyper.http20.stream.Stream
的用法示例。
在下文中一共展示了Stream._recv_cb方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_can_read_multiple_frames_from_streams
# 需要导入模块: from hyper.http20.stream import Stream [as 别名]
# 或者: from hyper.http20.stream.Stream import _recv_cb [as 别名]
def test_can_read_multiple_frames_from_streams(self):
out_frames = []
in_frames = []
def send_cb(frame):
out_frames.append(frame)
def recv_cb(s):
def inner():
s.receive_frame(in_frames.pop(0))
return inner
s = Stream(1, send_cb, None, None, None)
s._recv_cb = recv_cb(s)
s.state = STATE_HALF_CLOSED_LOCAL
# Provide two data frames to read.
f = DataFrame(1)
f.data = b'hi there!'
in_frames.append(f)
f = DataFrame(1)
f.data = b'hi there again!'
f.flags.add('END_STREAM')
in_frames.append(f)
data = s._read()
assert data == b'hi there!hi there again!'
assert len(out_frames) == 1
assert isinstance(out_frames[0], WindowUpdateFrame)
assert out_frames[0].window_increment == len(b'hi there!')
示例2: test_stream_reading_works
# 需要导入模块: from hyper.http20.stream import Stream [as 别名]
# 或者: from hyper.http20.stream.Stream import _recv_cb [as 别名]
def test_stream_reading_works(self):
out_frames = []
in_frames = []
def send_cb(frame):
out_frames.append(frame)
def recv_cb(s):
def inner():
s.receive_frame(in_frames.pop(0))
return inner
s = Stream(1, send_cb, None, None, None)
s._recv_cb = recv_cb(s)
s.state = STATE_HALF_CLOSED_LOCAL
# Provide a data frame to read.
f = DataFrame(1)
f.data = b'hi there!'
f.flags.add('END_STREAM')
in_frames.append(f)
data = s._read()
assert data == b'hi there!'
assert len(out_frames) == 0
示例3: test_flow_control_manager_update_includes_padding
# 需要导入模块: from hyper.http20.stream import Stream [as 别名]
# 或者: from hyper.http20.stream.Stream import _recv_cb [as 别名]
def test_flow_control_manager_update_includes_padding(self):
out_frames = []
in_frames = []
def send_cb(frame):
out_frames.append(frame)
def recv_cb(s):
def inner():
s.receive_frame(in_frames.pop(0))
return inner
start_window = 65535
s = Stream(1, send_cb, None, None, None, None, FlowControlManager(start_window))
s._recv_cb = recv_cb(s)
s.state = STATE_HALF_CLOSED_LOCAL
# Provide two data frames to read.
f = DataFrame(1)
f.data = b'hi there!'
f.pad_length = 10
f.flags.add('END_STREAM')
in_frames.append(f)
data = s._read()
assert data == b'hi there!'
assert s._in_window_manager.window_size == start_window - f.pad_length - len(data) - 1
示例4: test_reading_trailers_early_reads_all_data
# 需要导入模块: from hyper.http20.stream import Stream [as 别名]
# 或者: from hyper.http20.stream.Stream import _recv_cb [as 别名]
def test_reading_trailers_early_reads_all_data(self):
in_frames = []
headers = [('a', 'b'), ('c', 'd'), (':status', '200')]
trailers = [('e', 'f'), ('g', 'h')]
def recv_cb(s):
def inner():
s.receive_frame(in_frames.pop(0))
return inner
s = Stream(1, None, None, None, None, FixedDecoder(headers), FlowControlManager(65535))
s._recv_cb = recv_cb(s)
s.state = STATE_HALF_CLOSED_LOCAL
# Provide the first HEADERS frame.
f = HeadersFrame(1)
f.data = b'hi there!'
f.flags.add('END_HEADERS')
in_frames.append(f)
# Provide some data.
f = DataFrame(1)
f.data = b'testdata'
in_frames.append(f)
# Provide the trailers.
f = HeadersFrame(1)
f.data = b'hi there again!'
f.flags.add('END_STREAM')
f.flags.add('END_HEADERS')
in_frames.append(f)
# Begin by reading the first headers.
assert s.getheaders() == HTTPHeaderMap(headers)
# Now, replace the dummy decoder to ensure we get a new header block.
s._decoder = FixedDecoder(trailers)
# Ask for the trailers. This should also read the data frames.
assert s.gettrailers() == HTTPHeaderMap(trailers)
assert s.data == [b'testdata']
示例5: test_partial_reads_from_streams
# 需要导入模块: from hyper.http20.stream import Stream [as 别名]
# 或者: from hyper.http20.stream.Stream import _recv_cb [as 别名]
def test_partial_reads_from_streams(self):
out_frames = []
in_frames = []
def send_cb(frame):
out_frames.append(frame)
def recv_cb(s):
def inner():
s.receive_frame(in_frames.pop(0))
return inner
s = Stream(1, send_cb, None, None, None, None, FlowControlManager(65535))
s._recv_cb = recv_cb(s)
s.state = STATE_HALF_CLOSED_LOCAL
# Provide two data frames to read.
f = DataFrame(1)
f.data = b"hi there!"
in_frames.append(f)
f = DataFrame(1)
f.data = b"hi there again!"
f.flags.add("END_STREAM")
in_frames.append(f)
# We'll get the entire first frame.
data = s._read(4)
assert data == b"hi there!"
assert len(out_frames) == 1
# Now we'll get the entire of the second frame.
data = s._read(4)
assert data == b"hi there again!"
assert len(out_frames) == 1
assert s.state == STATE_CLOSED
示例6: test_can_read_single_frames_from_streams
# 需要导入模块: from hyper.http20.stream import Stream [as 别名]
# 或者: from hyper.http20.stream.Stream import _recv_cb [as 别名]
def test_can_read_single_frames_from_streams(self):
out_frames = []
in_frames = []
def send_cb(frame, tolerate_peer_gone=False):
out_frames.append(frame)
def recv_cb(s):
def inner():
s.receive_frame(in_frames.pop(0))
return inner
s = Stream(1, send_cb, None, None, None, None, FlowControlManager(800))
s._recv_cb = recv_cb(s)
s.state = STATE_HALF_CLOSED_LOCAL
# Provide two data frames to read.
f = DataFrame(1)
f.data = b'hi there!'
in_frames.append(f)
f = DataFrame(1)
f.data = b'hi there again!'
f.flags.add('END_STREAM')
in_frames.append(f)
data = s._read_one_frame()
assert data == b'hi there!'
data = s._read_one_frame()
assert data == b'hi there again!'
data = s._read_one_frame()
assert data is None
data = s._read()
assert data == b''