a c(.@svddlZddlmZddlmZmZddlmZmZm Z m Z m Z m Z ddl mZmZddlmZmZddlmZmZmZgd Zeed Zeed ZGd d d eZed ddGdddeZed ddGdddeZed ddGdddeZed ddGdddeZ ed ddGdddeZ!ed ddGdddeZ"eddGdddeZ#dS)N)ABC) dataclassfield)AnycastDictListTupleUnion)methodrequest_target)Headersnormalize_and_validate)bytesifyLocalProtocolErrorvalidate)EventRequestInformationalResponseResponseData EndOfMessageConnectionClosedasciic@seZdZdZdZdS)rz$ Base class for h11 events. N)__name__ __module__ __qualname____doc__ __slots__rrrX/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/h11/_events.pyr srFT)initfrozenc seZdZUdZdZeed<eed<eed<eed<ddd eee feee e eefe e e e ffeee feee fe d d fd d Z d ZZS)ranThe beginning of an HTTP request. Fields: .. attribute:: method An HTTP method, e.g. ``b"GET"`` or ``b"POST"``. Always a byte string. :term:`Bytes-like objects ` and native strings containing only ascii characters will be automatically converted to byte strings. .. attribute:: target The target of an HTTP request, e.g. ``b"/index.html"``, or one of the more exotic formats described in `RFC 7320, section 5.3 `_. Always a byte string. :term:`Bytes-like objects ` and native strings containing only ascii characters will be automatically converted to byte strings. .. attribute:: headers Request headers, represented as a list of (name, value) pairs. See :ref:`the header normalization rules ` for details. .. attribute:: http_version The HTTP protocol version, represented as a byte string like ``b"1.1"``. See :ref:`the HTTP version normalization rules ` for details. )r headerstarget http_versionr r$r%r&1.1F)r&_parsedN)r r$r%r&r(returnc stt|tr$t|d|nt|dt||d|svt|dt|t|dt|t|dt|n*t|d|t|d|t|d|d}|jD]\}}|dkr|d7}q|j d kr|dkrt d |dkrt d t t |j d t t|jd dS)Nr$r(r r%r&rshostr r'zMissing mandatory Host: headerzFound multiple Host: headerszIllegal method characterszIllegal target characters)super__init__ isinstancerobject __setattr__rrr$r&rr method_rer request_target_rer%) selfr r$r%r&r(Z host_countnamevalue __class__rr!r,Rs.   zRequest.__init__)rrrrr bytes__annotations__rr strrr boolr,__hash__ __classcell__rrr5r!r(s" ! $  +rcseZdZUdZeed<eed<eed<eed<dddd eee e eefe e e e ffeeee feee fe d d fd d Z d dddZd ZZS) _ResponseBase)r$r&reason status_coder$r&r>r?r'F)r&r>r(N)r$r?r&r>r(r)cstt|tr$t|d|nt|dt||d|st|dt|t|dt|t|tstt dt|dt|n*t|d|t|d|t|d|| dS)Nr$r*r>r&zstatus code must be integerr?) r+r,r-rr.r/rrintr __post_init__)r2r$r?r&r>r(r5rr!r,s   z_ResponseBase.__init__r)cCsdS)Nrr2rrr!rBsz_ResponseBase.__post_init__)rrrr rr8r7rAr rr r9r:r,rBr;r<rrr5r!r=s$ $  r=c@s"eZdZdZddddZdZdS)raAn HTTP informational response. Fields: .. attribute:: status_code The status code of this response, as an integer. For an :class:`InformationalResponse`, this is always in the range [100, 200). .. attribute:: headers Request headers, represented as a list of (name, value) pairs. See :ref:`the header normalization rules ` for details. .. attribute:: http_version The HTTP protocol version, represented as a byte string like ``b"1.1"``. See :ref:`the HTTP version normalization rules ` for details. .. attribute:: reason The reason phrase of this response, as a byte string. For example: ``b"OK"``, or ``b"Not Found"``. NrCcCs,d|jkrdks(ntd|jdS)NdzGInformationalResponse status_code should be in range [100, 200), not {}r?rformatrDrrr!rBs z#InformationalResponse.__post_init__rrrrrBr;rrrr!rsrc@s"eZdZdZddddZdZdS)raThe beginning of an HTTP response. Fields: .. attribute:: status_code The status code of this response, as an integer. For an :class:`Response`, this is always in the range [200, 1000). .. attribute:: headers Request headers, represented as a list of (name, value) pairs. See :ref:`the header normalization rules ` for details. .. attribute:: http_version The HTTP protocol version, represented as a byte string like ``b"1.1"``. See :ref:`the HTTP version normalization rules ` for details. .. attribute:: reason The reason phrase of this response, as a byte string. For example: ``b"OK"``, or ``b"Not Found"``. NrCcCs,d|jkrdks(ntd|jdS)NrFiz;Response status_code should be in range [200, 1000), not {}rGrDrrr!rBs zResponse.__post_init__rIrrrr!rs rc@sHeZdZUdZdZeed<eed<eed<d eeeddd d ZdZ dS) raPart of an HTTP message body. Fields: .. attribute:: data A :term:`bytes-like object` containing part of a message body. Or, if using the ``combine=False`` argument to :meth:`Connection.send`, then any object that your socket writing code knows what to do with, and for which calling :func:`len` returns the number of bytes that will be written -- see :ref:`sendfile` for details. .. attribute:: chunk_start A marker that indicates whether this data object is from the start of a chunked transfer encoding chunk. This field is ignored when when a Data event is provided to :meth:`Connection.send`: it is only valid on events emitted from :meth:`Connection.next_event`. You probably shouldn't use this attribute at all; see :ref:`chunk-delimiters-are-bad` for details. .. attribute:: chunk_end A marker that indicates whether this data object is the last for a given chunked transfer encoding chunk. This field is ignored when when a Data event is provided to :meth:`Connection.send`: it is only valid on events emitted from :meth:`Connection.next_event`. You probably shouldn't use this attribute at all; see :ref:`chunk-delimiters-are-bad` for details. )data chunk_start chunk_endrJrKrLFN)rJrKrLr)cCs.t|d|t|d|t|d|dS)NrJrKrL)r.r/)r2rJrKrLrrr!r,+sz Data.__init__)FF) rrrrr r7r8r:r,r;rrrr!rs   rcsheZdZUdZdZeed<dddeeee e e fee e e fdfe ddfdd Z dZZS) rajThe end of an HTTP message. Fields: .. attribute:: headers Default value: ``[]`` Any trailing headers attached to this message, represented as a list of (name, value) pairs. See :ref:`the header normalization rules ` for details. Must be empty unless ``Transfer-Encoding: chunked`` is in use. )r$r$NF)r$r()r$r(r)csDt|durtg}nt|ts2t||d}t|d|dS)Nr*r$)r+r,rr-rr.r/)r2r$r(r5rr!r,Qs     zEndOfMessage.__init__)rrrrr rr8r rr r7r9r:r,r;r<rrr5r!r;s "r)r#c@seZdZdZdS)raAThis event indicates that the sender has closed their outgoing connection. Note that this does not necessarily mean that they can't *receive* further data, because TCP connections are composed to two one-way channels which can be closed independently. See :ref:`closing` for details. No fields. N)rrrrrrrr!res r)$reabcrZ dataclassesrrtypingrrrrr r Z_abnfr r _headersrrZ_utilrrr__all__compileencoder0r1rrr=rrrrrrrrr!s0    W . ) ) 7 )