U
    EZh.                     @   sp  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 d	d
dddddg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   R/home/aprabhat/apps/x.techxrdev.in/venv/lib/python3.8/site-packages/h11/_events.pyr       s   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	eee	f eee
eeef  e
ee	e	f  f eee	f eee	f ed
d 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"   _parsedN)r   r    r!   r"   r$   returnc          	         s  t    t|tr$t| d| nt| dt||d |svt| dt| t| dt| t| dt| n*t| d| t| d| t| d| d}| jD ]\}}|dkr|d7 }q| j	d	kr|dkrt
d
|dkrt
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$   Z
host_countnamevalue	__class__r   r   r(   R   s2    	

  

zRequest.__init__)r   r   r   r   r   bytes__annotations__r
   r   strr   r   boolr(   __hash____classcell__r   r   r1   r   r   (   s"   
!
$

+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	eee	e
eef  e	e
eef  f eeeef eeef ed
d fddZd
dddZd
Z  ZS )_ResponseBase)r    r"   reasonstatus_coder    r"   r:   r;   r#       F)r"   r:   r$   N)r    r;   r"   r:   r$   r%   c                   s   t    t|tr$t| d| nt| dt||d |st| dt| t| dt| t|tstt	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$   r1   r   r   r(      s$    	

  

z_ResponseBase.__init__r%   c                 C   s   d S )Nr   r.   r   r   r   r>      s    z_ResponseBase.__post_init__)r   r   r   r   r
   r4   r3   r=   r   r   r   r5   r6   r(   r>   r7   r8   r   r   r1   r   r9      s$   
$

r9   c                   @   s"   e Zd ZdZd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"``.

    Nr?   c                 C   s,   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__r   r   r   r   r>   r7   r   r   r   r   r      s   c                   @   s"   e Zd ZdZddddZdZdS )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"``.

    Nr?   c                 C   s,   d| j   krdk s(n td| j d S )NrB   i  z;Response status_code should be in range [200, 1000), not {}rC   r@   r   r   r   r>      s    zResponse.__post_init__rE   r   r   r   r   r      s   	c                   @   sH   e Zd ZU dZdZeed< eed< eed< deeedd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_endrF   rG   rH   FN)rF   rG   rH   r%   c                 C   s.   t | d| t | d| t | d| d S )NrF   rG   rH   )r*   r+   )r.   rF   rG   rH   r   r   r   r(   +  s    zData.__init__)FF)
r   r   r   r   r   r3   r4   r6   r(   r7   r   r   r   r   r     s   
      c                       sh   e Zd ZU dZdZeed< dddeeee	e
e
f  ee	eef  df edd 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$   r%   c                   sD   t    |d krtg }nt|ts2t||d}t| d| d S )Nr&   r    )r'   r(   r
   r)   r   r*   r+   )r.   r    r$   r1   r   r   r(   Q  s    


zEndOfMessage.__init__)r   r   r   r   r   r
   r4   r   r   r   r3   r5   r6   r(   r7   r8   r   r   r1   r   r   ;  s   
")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   
) reabcr   dataclassesr   typingr   r   r   Z_abnfr   r	   _headersr
   r   Z_utilr   r   r   __all__compileencoder,   r-   r   r   r9   r   r   r   r   r   r   r   r   r   <module>   s>   

W
.
)
)
7
)