Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_window_update_has_no_flags(self):
f = WindowUpdateFrame(0)
flags = f.parse_flags(0xFF)
assert not flags
assert isinstance(flags, Flags)
self._closed_streams = SizeLimitDict(
size_limit=self.MAX_CLOSED_STREAMS
)
# The flow control window manager for the connection.
self._inbound_flow_control_window_manager = WindowManager(
max_window_size=self.local_settings.initial_window_size
)
# When in doubt use dict-dispatch.
self._frame_dispatch_table = {
HeadersFrame: self._receive_headers_frame,
PushPromiseFrame: self._receive_push_promise_frame,
SettingsFrame: self._receive_settings_frame,
DataFrame: self._receive_data_frame,
WindowUpdateFrame: self._receive_window_update_frame,
PingFrame: self._receive_ping_frame,
RstStreamFrame: self._receive_rst_stream_frame,
PriorityFrame: self._receive_priority_frame,
GoAwayFrame: self._receive_goaway_frame,
ContinuationFrame: self._receive_naked_continuation,
AltSvcFrame: self._receive_alt_svc_frame,
ExtensionFrame: self._receive_unknown_frame
}
def _update_flow_control_window(self, stream_id, increment):
frm = hyperframe.frame.WindowUpdateFrame(stream_id=0, window_increment=increment)
self.send_frame(frm)
frm = hyperframe.frame.WindowUpdateFrame(stream_id=stream_id, window_increment=increment)
self.send_frame(frm)
stream_id, acknowledged_size
)
if stream_id <= 0:
raise ValueError(
"Stream ID %d is not valid for acknowledge_received_data" %
stream_id
)
if acknowledged_size < 0:
raise ValueError("Cannot acknowledge negative data")
frames = []
conn_manager = self._inbound_flow_control_window_manager
conn_increment = conn_manager.process_bytes(acknowledged_size)
if conn_increment:
f = WindowUpdateFrame(0)
f.window_increment = conn_increment
frames.append(f)
try:
stream = self._get_stream_by_id(stream_id)
except StreamClosedError:
# The stream is already gone. We're not worried about incrementing
# the window in this case.
pass
else:
# No point incrementing the windows of closed streams.
if stream.open:
frames.extend(
stream.acknowledge_received_data(acknowledged_size)
)
def _update_flow_control_window(self, stream_id, increment):
frm = hyperframe.frame.WindowUpdateFrame(stream_id=0, window_increment=increment)
self.send_frame(frm)
frm = hyperframe.frame.WindowUpdateFrame(stream_id=stream_id, window_increment=increment)
self.send_frame(frm)
def increase_flow_control_window(self, increment):
"""
Increase the size of the flow control window for the remote side.
"""
self.config.logger.debug(
"Increase flow control window for %r by %d",
self, increment
)
self.state_machine.process_input(StreamInputs.SEND_WINDOW_UPDATE)
self._inbound_window_manager.window_opened(increment)
wuf = WindowUpdateFrame(self.stream_id)
wuf.window_increment = increment
return [wuf]
# Data that needs to be sent.
self._data_to_send = b''
# Keeps track of streams that have been forcefully reset by this peer.
# Used to ensure that we don't blow up in the face of frames that were
# in flight when a stream was reset.
self._reset_streams = set()
# When in doubt use dict-dispatch.
self._frame_dispatch_table = {
HeadersFrame: self._receive_headers_frame,
PushPromiseFrame: self._receive_push_promise_frame,
SettingsFrame: self._receive_settings_frame,
DataFrame: self._receive_data_frame,
WindowUpdateFrame: self._receive_window_update_frame,
PingFrame: self._receive_ping_frame,
RstStreamFrame: self._receive_rst_stream_frame,
PriorityFrame: self._receive_priority_frame,
GoAwayFrame: self._receive_goaway_frame,
ContinuationFrame: self._receive_naked_continuation,
AltSvcFrame: self._receive_alt_svc_frame,
}
self.MAX_WINDOW_INCREMENT
)
self.state_machine.process_input(ConnectionInputs.SEND_WINDOW_UPDATE)
if stream_id is not None:
stream = self.streams[stream_id]
frames = stream.increase_flow_control_window(
increment
)
stream.inbound_flow_control_window = guard_increment_window(
stream.inbound_flow_control_window,
increment
)
else:
f = WindowUpdateFrame(0)
f.window_increment = increment
self.inbound_flow_control_window = guard_increment_window(
self.inbound_flow_control_window,
increment
)
frames = [f]
self._prepare_for_sending(frames)
def increase_flow_control_window(self, increment):
"""
Increase the size of the flow control window for the remote side.
"""
self.config.logger.debug(
"Increase flow control window for %r by %d",
self, increment
)
self.state_machine.process_input(StreamInputs.SEND_WINDOW_UPDATE)
self._inbound_window_manager.window_opened(increment)
wuf = WindowUpdateFrame(self.stream_id)
wuf.window_increment = increment
return [wuf]