Format: application/x-python-code
⬇ Download File (9.9 KB)
   1  o
   2  
   3  .'h(.�@svddlZddlmZddlmZmZddlmZmZm	Z	m
   4  Z
   5  mZmZddl
   6  mZmZddlmZmZddlmZmZmZgd	�Ze�e�d
   7  ��Ze�e�d
   8  ��ZGdd�de�Zed
   9  dd�Gdd�de��Zed
  10  dd�Gdd�de��Zed
  11  dd�Gdd�de��Zed
  12  dd�Gdd�de��Z ed
  13  dd�Gdd�de��Z!ed
  14  dd�Gdd�de��Z"edd�Gdd�de��Z#dS)�N)�ABC)�	dataclass�field)�Any�cast�Dict�List�Tuple�Union�)�method�request_target)�Headers�normalize_and_validate)�bytesify�LocalProtocolError�validate)�Event�Request�InformationalResponse�Response�Data�EndOfMessage�ConnectionClosed�asciic@seZdZdZdZdS)rz$
  15      Base class for h11 events.
  16      �N)�__name__�
  17  __module__�__qualname__�__doc__�	__slots__rrr�AC:\Users\shubh\Videos\agent\nova\Lib\site-packages\h11/_events.pyr srFT)�init�frozenc
  18  s�eZdZUdZdZeed<eed<eed<eed<ddd	�deee	fdeee
  19  eeefe
  20  ee	e	ffdeee	fdeee	fd
  21  eddf�fd
  22  d�Z
  23  dZ�ZS)ranThe beginning of an HTTP request.
  24  
  25      Fields:
  26  
  27      .. attribute:: method
  28  
  29         An HTTP method, e.g. ``b"GET"`` or ``b"POST"``. Always a byte
  30         string. :term:`Bytes-like objects <bytes-like object>` and native
  31         strings containing only ascii characters will be automatically
  32         converted to byte strings.
  33  
  34      .. attribute:: target
  35  
  36         The target of an HTTP request, e.g. ``b"/index.html"``, or one of the
  37         more exotic formats described in `RFC 7320, section 5.3
  38         <https://tools.ietf.org/html/rfc7230#section-5.3>`_. Always a byte
  39         string. :term:`Bytes-like objects <bytes-like object>` and native
  40         strings containing only ascii characters will be automatically
  41         converted to byte strings.
  42  
  43      .. attribute:: headers
  44  
  45         Request headers, represented as a list of (name, value) pairs. See
  46         :ref:`the header normalization rules <headers-format>` for details.
  47  
  48      .. attribute:: http_version
  49  
  50         The HTTP protocol version, represented as a byte string like
  51         ``b"1.1"``. See :ref:`the HTTP version normalization rules
  52         <http_version-format>` for details.
  53  
  54      )r�headers�target�http_versionrr$r%r&�1.1F)r&�_parsedr(�returnNc	st���t|t�rt�|d|�nt�|dt||d��|s;t�|dt|��t�|dt|��t�|dt|��nt�|d|�t�|d|�t�|d|�d}|jD]\}}|dkra|d7}qU|j	d	kro|dkrot
  55  d
  56  ��|dkrwt
  57  d��tt|j
  58  d�tt|jd
  59  �dS)Nr$�r(rr%r&rshostrr'zMissing mandatory Host: headerzFound multiple Host: headerszIllegal method characterszIllegal target characters)�super�__init__�
  60  isinstancer�object�__setattr__rrr$r&rr�	method_rer�request_target_rer%)	�selfrr$r%r&r(Z
  61  host_count�name�value��	__class__rr!r,Rs0
  62  	
  63  ��zRequest.__init__)rrrrr �bytes�__annotations__rr
  64  �strrr	�boolr,�__hash__�
  65  __classcell__rrr5r!r(s.
  66  !�
  67  �$�
  68  �
  69  ���+rc
  70  s�eZdZUdZeed<eed<eed<eed<dddd	�deee	e
  71  eefe	e
  72  eeffdedeeefdeeefd
  73  eddf�fd
  74  d�Z
  75  ddd�ZdZ�ZS)�
  76  _ResponseBase)r$r&�reason�status_coder$r&r>r?r'�F)r&r>r(r(r)Ncs�t���t|t�rt�|d|�nt�|dt||d��|sDt�|dt|��t�|dt|��t|t�s:t	d��t�|dt|��nt�|d|�t�|d|�t�|d|�|�
  77  �dS)Nr$r*r>r&zstatus code must be integerr?)r+r,r-rr.r/rr�intr�
  78  __post_init__)r2r$r?r&r>r(r5rr!r,�s 
  79  	
  80  �
  81  z_ResponseBase.__init__cCsdS)Nr�r2rrr!rB�sz_ResponseBase.__post_init__�r)N)rrrr rr8r7rAr
  82  rr	r9r:r,rBr;r<rrr5r!r=�s0
  83  �$��
  84  �
  85  ���
  86  r=c@�eZdZdZddd�ZdZdS)raAn HTTP informational response.
  87  
  88      Fields:
  89  
  90      .. attribute:: status_code
  91  
  92         The status code of this response, as an integer. For an
  93         :class:`InformationalResponse`, this is always in the range [100,
  94         200).
  95  
  96      .. attribute:: headers
  97  
  98         Request headers, represented as a list of (name, value) pairs. See
  99         :ref:`the header normalization rules <headers-format>` for
 100         details.
 101  
 102      .. attribute:: http_version
 103  
 104         The HTTP protocol version, represented as a byte string like
 105         ``b"1.1"``. See :ref:`the HTTP version normalization rules
 106         <http_version-format>` for details.
 107  
 108      .. attribute:: reason
 109  
 110         The reason phrase of this response, as a byte string. For example:
 111         ``b"OK"``, or ``b"Not Found"``.
 112  
 113      r)NcC�,d|jkrdksntd�|j���dS)N�d��zGInformationalResponse status_code should be in range [100, 200), not {}�r?r�formatrCrrr!rB�s��z#InformationalResponse.__post_init__rD�rrrrrBr;rrrr!r�s
 114  rc@rE)ra�The beginning of an HTTP response.
 115  
 116      Fields:
 117  
 118      .. attribute:: status_code
 119  
 120         The status code of this response, as an integer. For an
 121         :class:`Response`, this is always in the range [200,
 122         1000).
 123  
 124      .. attribute:: headers
 125  
 126         Request headers, represented as a list of (name, value) pairs. See
 127         :ref:`the header normalization rules <headers-format>` for details.
 128  
 129      .. attribute:: http_version
 130  
 131         The HTTP protocol version, represented as a byte string like
 132         ``b"1.1"``. See :ref:`the HTTP version normalization rules
 133         <http_version-format>` for details.
 134  
 135      .. attribute:: reason
 136  
 137         The reason phrase of this response, as a byte string. For example:
 138         ``b"OK"``, or ``b"Not Found"``.
 139  
 140      r)NcCrF)NrHi�z;Response status_code should be in range [200, 1000), not {}rIrCrrr!rB�s���zResponse.__post_init__rDrKrrrr!r�s
 141  	rc	@sPeZdZUdZdZeed<eed<eed<	ddedededdfd	d
 142  �ZdZ	dS)raPart of an HTTP message body.
 143  
 144      Fields:
 145  
 146      .. attribute:: data
 147  
 148         A :term:`bytes-like object` containing part of a message body. Or, if
 149         using the ``combine=False`` argument to :meth:`Connection.send`, then
 150         any object that your socket writing code knows what to do with, and for
 151         which calling :func:`len` returns the number of bytes that will be
 152         written -- see :ref:`sendfile` for details.
 153  
 154      .. attribute:: chunk_start
 155  
 156         A marker that indicates whether this data object is from the start of a
 157         chunked transfer encoding chunk. This field is ignored when when a Data
 158         event is provided to :meth:`Connection.send`: it is only valid on
 159         events emitted from :meth:`Connection.next_event`. You probably
 160         shouldn't use this attribute at all; see
 161         :ref:`chunk-delimiters-are-bad` for details.
 162  
 163      .. attribute:: chunk_end
 164  
 165         A marker that indicates whether this data object is the last for a
 166         given chunked transfer encoding chunk. This field is ignored when when
 167         a Data event is provided to :meth:`Connection.send`: it is only valid
 168         on events emitted from :meth:`Connection.next_event`. You probably
 169         shouldn't use this attribute at all; see
 170         :ref:`chunk-delimiters-are-bad` for details.
 171  
 172      )�data�chunk_start�	chunk_endrLrMrNFr)NcCs.t�|d|�t�|d|�t�|d|�dS)NrLrMrN)r.r/)r2rLrMrNrrr!r,+sz
 173  Data.__init__)FF)
 174  rrrrr r7r8r:r,r;rrrr!rs"
 175   ����
 176  �rc	sleZdZUdZdZeed<ddd�deeee	e
 177  e
 178  fee	eefdfdeddf�fd	d
 179  �Z
 180  dZ�ZS)rajThe end of an HTTP message.
 181  
 182      Fields:
 183  
 184      .. attribute:: headers
 185  
 186         Default value: ``[]``
 187  
 188         Any trailing headers attached to this message, represented as a list of
 189         (name, value) pairs. See :ref:`the header normalization rules
 190         <headers-format>` for details.
 191  
 192         Must be empty unless ``Transfer-Encoding: chunked`` is in use.
 193  
 194      )r$r$NF)r$r(r(r)csDt���|durtg�}nt|t�st||d�}t�|d|�dS)Nr*r$)r+r,rr-rr.r/)r2r$r(r5rr!r,Qs
 195  
 196  
 197  zEndOfMessage.__init__)rrrrr rr8r
 198  rr	r7r9r:r,r;r<rrr5r!r;s 
 199  �"����r)r#c@seZdZdZdS)raAThis event indicates that the sender has closed their outgoing
 200      connection.
 201  
 202      Note that this does not necessarily mean that they can't *receive* further
 203      data, because TCP connections are composed to two one-way channels which
 204      can be closed independently. See :ref:`closing` for details.
 205  
 206      No fields.
 207      N)rrrrrrrr!res
 208  r)$�re�abcr�dataclassesrr�typingrrrrr	r
 209  Z_abnfrr
 210  �_headersrrZ_utilrrr�__all__�compile�encoder0r1rrr=rrrrrrrrr!�<module>s2 
 211  
 212  
 213  W
 214  .
 215  )
 216  )
 217  7)