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_priority_tree_raises_error_inserting_duplicate(self):
"""
Attempting to insert a stream that is already in the tree raises a
DuplicateStreamError
"""
p = priority.PriorityTree()
p.insert_stream(1)
with pytest.raises(priority.DuplicateStreamError):
p.insert_stream(1)
def insert_stream(self, stream_id):
try:
self.tree.insert_stream(stream_id)
except priority.DuplicateStreamError:
assert stream_id in self.stream_ids
else:
assert stream_id not in self.stream_ids
self.stream_ids.add(stream_id)
"""
stream = H2Stream(
event.stream_id,
self, event.headers,
self.requestFactory,
self.site,
self.factory
)
self.streams[event.stream_id] = stream
self._streamCleanupCallbacks[event.stream_id] = Deferred()
self._outboundStreamQueues[event.stream_id] = deque()
# Add the stream to the priority tree but immediately block it.
try:
self.priority.insert_stream(event.stream_id)
except priority.DuplicateStreamError:
# Stream already in the tree. This can happen if we received a
# PRIORITY frame before a HEADERS frame. Just move on: we set the
# stream up properly in _handlePriorityUpdate.
pass
else:
self.priority.block(event.stream_id)
"""
stream = H2Stream(
event.stream_id,
self, event.headers,
self.requestFactory,
self.site,
self.factory
)
self.streams[event.stream_id] = stream
self._streamCleanupCallbacks[event.stream_id] = Deferred()
self._outboundStreamQueues[event.stream_id] = deque()
# Add the stream to the priority tree but immediately block it.
try:
self.priority.insert_stream(event.stream_id)
except priority.DuplicateStreamError:
# Stream already in the tree. This can happen if we received a
# PRIORITY frame before a HEADERS frame. Just move on: we set the
# stream up properly in _handlePriorityUpdate.
pass
else:
self.priority.block(event.stream_id)
received request.
@type event: L{h2.events.RequestReceived}
"""
stream = H2Stream(
event.stream_id, self, event.headers, self.requestFactory
)
stream.site = self.site
stream.factory = self.factory
self.streams[event.stream_id] = stream
self._streamCleanupCallbacks[event.stream_id] = Deferred()
self._outboundStreamQueues[event.stream_id] = deque()
# Add the stream to the priority tree but immediately block it.
try:
self.priority.insert_stream(event.stream_id)
except priority.DuplicateStreamError:
# Stream already in the tree. This can happen if we received a
# PRIORITY frame before a HEADERS frame. Just move on: we set the
# stream up properly in _handlePriorityUpdate.
pass
else:
self.priority.block(event.stream_id)
request.stream_id,
)
else:
self.streams[request.stream_id] = HTTPStream(
self.config,
self.ssl,
self.client,
self.server,
self.stream_send,
self.spawn_app,
request.stream_id,
)
self.stream_buffers[request.stream_id] = StreamBuffer(self.event_class)
try:
self.priority.insert_stream(request.stream_id)
except priority.DuplicateStreamError:
# Recieved PRIORITY frame before HEADERS frame
pass
else:
self.priority.block(request.stream_id)
await self.streams[request.stream_id].handle(
Request(
stream_id=request.stream_id,
headers=filter_pseudo_headers(request.headers),
http_version="2",
method=method,
raw_path=raw_path,
)