o
    MK&h.                     @   sf  d dl Z d dlmZ d dlmZ d dlmZmZmZ ddl	m
Z
mZ ddlmZmZ ddlmZmZmZ g d	Ze e
d
Ze ed
ZG dd deZedddG dd deZedddG dd deZedddG dd deZedddG dd deZedddG dd deZedddG dd deZeddG dd deZdS )    N)ABC)	dataclass)ListTupleUnion   )methodrequest_target)Headersnormalize_and_validate)bytesifyLocalProtocolErrorvalidate)EventRequestInformationalResponseResponseDataEndOfMessageConnectionClosedasciic                   @   s   e Zd ZdZdZdS )r   z$
    Base class for h11 events.
     N)__name__
__module____qualname____doc__	__slots__r   r   r   >/var/www/html/venv/lib/python3.10/site-packages/h11/_events.pyr       s    r   FT)initfrozenc                       s   e Zd ZU dZdZeed< eed< eed< eed< ddd	deee	f deee
eeef  e
ee	e	f  f deee	f deee	f d
eddf fddZdZ  ZS )r   an  The 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 <bytes-like object>` 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
       <https://tools.ietf.org/html/rfc7230#section-5.3>`_. Always a byte
       string. :term:`Bytes-like objects <bytes-like object>` 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 <headers-format>` 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
       <http_version-format>` for details.

    )r   headerstargethttp_versionr   r    r!   r"      1.1F)r"   _parsedr$   returnNc          	         s  t    t|trt| d| nt| dt||d |s;t| dt| t| dt| t| dt| nt| d| t| d| t| d| d}| jD ]\}}|dkra|d7 }qU| j	d	kro|dkrot
d
|dkrwt
dtt| jd tt| jd d S )Nr    r$   r   r!   r"   r   s   hostr   r#   zMissing mandatory Host: headerzFound multiple Host: headerszIllegal method characterszIllegal target characters)super__init__
isinstancer
   object__setattr__r   r   r    r"   r   r   	method_rer   request_target_rer!   )	selfr   r    r!   r"   r$   
host_countnamevalue	__class__r   r   r(   R   s0   
	
zRequest.__init__)r   r   r   r   r   bytes__annotations__r
   r   strr   r   boolr(   __hash____classcell__r   r   r2   r   r   (   s.   
 !
$

+r   c                       s   e Zd ZU dZeed< eed< eed< eed< dddd	deee	e
eef  e	e
eef  f dedeeef deeef d
eddf fddZdddZdZ  ZS )_ResponseBase)r    r"   reasonstatus_coder    r"   r;   r<   r#       F)r"   r;   r$   r$   r%   Nc                   s   t    t|trt| d| nt| dt||d |sDt| dt| t| dt| t|ts:t	dt| dt| nt| d| t| d| t| d| | 
  d S )Nr    r&   r;   r"   zstatus code must be integerr<   )r'   r(   r)   r
   r*   r+   r   r   intr   __post_init__)r.   r    r<   r"   r;   r$   r2   r   r   r(      s    
	

z_ResponseBase.__init__c                 C   s   d S )Nr   r.   r   r   r   r?      s   z_ResponseBase.__post_init__r%   N)r   r   r   r   r
   r5   r4   r>   r   r   r   r6   r7   r(   r?   r8   r9   r   r   r2   r   r:      s0   
 $


r:   c                   @      e Zd ZdZdddZdZdS )r   a  An 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 <headers-format>` 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
       <http_version-format>` for details.

    .. attribute:: reason

       The reason phrase of this response, as a byte string. For example:
       ``b"OK"``, or ``b"Not Found"``.

    r%   Nc                 C   ,   d| j   krdk sn td| j d S )Nd      zGInformationalResponse status_code should be in range [100, 200), not {}r<   r   formatr@   r   r   r   r?      s   z#InformationalResponse.__post_init__rA   r   r   r   r   r?   r8   r   r   r   r   r      s    
r   c                   @   rB   )r   a  The 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 <headers-format>` 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
       <http_version-format>` for details.

    .. attribute:: reason

       The reason phrase of this response, as a byte string. For example:
       ``b"OK"``, or ``b"Not Found"``.

    r%   Nc                 C   rC   )NrE   i  z;Response status_code should be in range [200, 1000), not {}rF   r@   r   r   r   r?      s   zResponse.__post_init__rA   rH   r   r   r   r   r      s    
	r   c                	   @   sP   e Zd ZU dZdZeed< eed< eed< 	ddedededdfd	d
ZdZ	dS )r   a  Part 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_endrI   rJ   rK   Fr%   Nc                 C   s.   t | d| t | d| t | d| d S )NrI   rJ   rK   )r*   r+   )r.   rI   rJ   rK   r   r   r   r(   +  s   zData.__init__)FF)
r   r   r   r   r   r4   r5   r7   r(   r8   r   r   r   r   r     s"   
  
r   c                	       sl   e Zd ZU dZdZeed< ddddeeee	e
e
f  ee	eef  df deddf fd	d
ZdZ  ZS )r   aj  The 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
       <headers-format>` for details.

       Must be empty unless ``Transfer-Encoding: chunked`` is in use.

    )r    r    NF)r    r$   r$   r%   c                   sD   t    |d u rtg }nt|tst||d}t| d| d S )Nr&   r    )r'   r(   r
   r)   r   r*   r+   )r.   r    r$   r2   r   r   r(   Q  s   


zEndOfMessage.__init__)r   r   r   r   r   r
   r5   r   r   r   r4   r6   r7   r(   r8   r9   r   r   r2   r   r   ;  s    
 "r   )r   c                   @   s   e Zd ZdZdS )r   aA  This 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)r   r   r   r   r   r   r   r   r   e  s    
r   ) reabcr   dataclassesr   typingr   r   r   _abnfr   r	   _headersr
   r   _utilr   r   r   __all__compileencoder,   r-   r   r   r:   r   r   r   r   r   r   r   r   r   <module>   s2   


W
.
)
)
7)