File: //lib/python3/dist-packages/twisted/web/__pycache__/_http2.cpython-38.pyc
U
s�@g"� � @ sb d Z ddlmZmZ ddlZddlZddlZddlmZ ddl m
Z
ddlZddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlmZ ddlmZ ddlmZmZmZmZmZ dd lmZ dd
lmZ ddl m!Z! ddl"m#Z# dd
l$m%Z% ddl&m'Z' g Z(e)� Z*ej+dk �rej,de-dd� e.d��e
ee�G dd� dee#��Z/e
eee�G dd� de)��Z0dd� Z1dS )a�
HTTP2 Implementation
This is the basic server-side protocol implementation used by the Twisted
Web server for HTTP2. This functionality is intended to be combined with the
HTTP/1.1 and HTTP/1.0 functionality in twisted.web.http to provide complete
protocol support for HTTP-type protocols.
This API is currently considered private because it's in early draft form. When
it has stabilised, it'll be made public.
� )�absolute_import�divisionN)�deque)�implementer)�Deferred)�ConnectionLost)� IProtocol�
ITransport� IConsumer�
IPushProducer�
ISSLTransport)�_PullToPush)�Protocol)�Logger)�TimeoutMixin)�Failure)�ExcessiveBufferingError)� � � zrHTTP/2 cannot be enabled because this version of Python is too old, and does not fully support memoryview objects.r )�
stacklevelz,HTTP/2 not supported on this Python version.c @ s" e Zd ZdZdZdZdZe� ZdZ dCdd�Z
dd� Zdd � Zd
d� Z
dd
� ZdDdd�Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd � Zd!d"� Zd#d$� Zd%d&� Zd'd(� Zd)d*� Zd+d,� Zd-d.� Zd/d0� Zd1d2� Z d3d4� Z!d5d6� Z"d7d8� Z#d9d:� Z$d;d<� Z%d=d>� Z&d?d@� Z'dAdB� Z(dS )E�H2Connectiona
A class representing a single HTTP/2 connection.
This implementation of L{IProtocol} works hand in hand with L{H2Stream}.
This is because we have the requirement to register multiple producers for
a single HTTP/2 connection, one for each stream. The standard Twisted
interfaces don't really allow for this, so instead there's a custom
interface between the two objects that allows them to work hand-in-hand here.
@ivar conn: The HTTP/2 connection state machine.
@type conn: L{h2.connection.H2Connection}
@ivar streams: A mapping of stream IDs to L{H2Stream} objects, used to call
specific methods on streams when events occur.
@type streams: L{dict}, mapping L{int} stream IDs to L{H2Stream} objects.
@ivar priority: A HTTP/2 priority tree used to ensure that responses are
prioritised appropriately.
@type priority: L{priority.PriorityTree}
@ivar _consumerBlocked: A flag tracking whether or not the L{IConsumer}
that is consuming this data has asked us to stop producing.
@type _consumerBlocked: L{bool}
@ivar _sendingDeferred: A L{Deferred} used to restart the data-sending loop
when more response data has been produced. Will not be present if there
is outstanding data still to send.
@type _consumerBlocked: A L{twisted.internet.defer.Deferred}, or L{None}
@ivar _outboundStreamQueues: A map of stream IDs to queues, used to store
data blocks that are yet to be sent on the connection. These are used
both to handle producers that do not respect L{IConsumer} but also to
allow priority to multiplex data appropriately.
@type _outboundStreamQueues: A L{dict} mapping L{int} stream IDs to
L{collections.deque} queues, which contain either L{bytes} objects or
C{_END_STREAM_SENTINEL}.
@ivar _sender: A handle to the data-sending loop, allowing it to be
terminated if needed.
@type _sender: L{twisted.internet.task.LoopingCall}
@ivar abortTimeout: The number of seconds to wait after we attempt to shut
the transport down cleanly to give up and forcibly terminate it. This
is only used when we time a connection out, to prevent errors causing
the FD to get leaked. If this is L{None}, we will wait forever.
@type abortTimeout: L{int}
@ivar _abortingCall: The L{twisted.internet.base.DelayedCall} that will be
used to forcibly close the transport if it doesn't close cleanly.
@type _abortingCall: L{twisted.internet.base.DelayedCall}
N� c C s� t jjdd d�}t jj|d�| _i | _t�� | _d | _ d | _
i | _i | _d| _
d| _t� | _d| _|d krvddlm} || _| j�d| j� d S )NF)Zclient_sideZheader_encoding)�configTi D r )�reactor)�h2r ZH2Configuration�
connectionr �conn�streams�priorityZPriorityTree�_consumerBlocked�_sendingDeferred�_outboundStreamQueues�_streamCleanupCallbacks�_stillProducing�_maxBufferedControlFrameBytesr �_bufferedControlFrames�_bufferedControlFrameBytesZtwisted.internetr �_reactor� callLater�_sendPrioritisedData)�selfr r � r, �4/usr/lib/python3/dist-packages/twisted/web/_http2.py�__init__� s&