本文整理汇总了Python中hyper.http20.stream.Stream.gettrailers方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.gettrailers方法的具体用法?Python Stream.gettrailers怎么用?Python Stream.gettrailers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hyper.http20.stream.Stream
的用法示例。
在下文中一共展示了Stream.gettrailers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reading_trailers_early_reads_all_data
# 需要导入模块: from hyper.http20.stream import Stream [as 别名]
# 或者: from hyper.http20.stream.Stream import gettrailers [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']