Ë
    Û�ði  ã                   ó$   — d Z ddlZ G d„ d«      Zy)zt
Async version of gunicorn/http/unreader.py for ASGI workers.

Provides async reading with pushback buffer support.
é    Nc                   óD   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zdd„Zd„ Z	d	„ Z
d
„ Zy)ÚAsyncUnreadera8  Async socket reader with pushback buffer support.

    This class wraps an asyncio StreamReader and provides the ability
    to "unread" data back into a buffer for re-parsing.

    Performance optimization: Reuses BytesIO buffer with truncate/seek
    instead of creating new objects to reduce GC pressure.
    c                 ó`   — || _         t        j                  «       | _        || _        d| _        y)z�Initialize the async unreader.

        Args:
            reader: asyncio.StreamReader instance
            max_chunk: Maximum bytes to read at once
        r   N)ÚreaderÚioÚBytesIOÚbufÚ	max_chunkÚ
_buf_start)Úselfr   r
   s      úQ/var/www/html/Extract/venv/lib/python3.12/site-packages/gunicorn/asgi/unreader.pyÚ__init__zAsyncUnreader.__init__   s&   € ð ˆŒÜ—:‘:“<ˆŒØ"ˆŒØˆ�ó    c                 ó~   — | j                   j                  d«       | j                   j                  d«       d| _        y)z7Reset buffer for reuse instead of creating new BytesIO.r   N)r	   ÚseekÚtruncater   ©r   s    r   Ú_reset_bufferzAsyncUnreader._reset_buffer$   s+   € à�‰�‰�aÔØ�‰×Ñ˜!ÔØˆ�r   c                 ó¤   — | j                   j                  | j                  «       | j                   j                  «       }| j	                  «        |S )z'Get all buffered data and reset buffer.)r	   r   r   Úreadr   )r   Údatas     r   Ú_get_buffered_dataz AsyncUnreader._get_buffered_data*   s6   € à�‰�‰�d—o‘oÔ&Ø�x‰x�}‰}‹ˆØ×ÑÔØˆr   c                 ót   — | j                   j                  dt        j                  «      }|| j                  z
  S )zGet size of buffered data.r   )r	   r   r   ÚSEEK_ENDr   )r   Úends     r   Ú_buffer_sizezAsyncUnreader._buffer_size1   s)   € à�h‰h�m‰m˜AœrŸ{™{Ó+ˆØ�T—_‘_Ñ$Ð$r   Nc              ƒ   ó^  K  — |�t        |t        «      st        d«      ‚|�|dk(  ry|dk  rd}| j                  «       }|€|dkD  r| j	                  «       S |€| j                  «       ƒ d{  –—† }|S ||k  rƒ| j                  «       ƒ d{  –—† }|s| j	                  «       S | j                  j                  dt        j                  «       | j                  j                  |«       |t        |«      z  }||k  rŒƒ| j                  j                  | j                  «       | j                  j                  |«      }| xj                  |z  c_        | j                  dkD  rG| j                  j                  «       }| j                  «        |r| j                  j                  |«       |S 7 �Œ<7 �Œ ­w)a  Read data from the stream, using buffered data first.

        Args:
            size: Number of bytes to read. If None, returns all buffered
                  data or reads a single chunk.

        Returns:
            bytes: Data read from buffer or stream
        Nz&size parameter must be an int or long.r   r   é    )Ú
isinstanceÚintÚ	TypeErrorr   r   Ú_read_chunkr	   r   r   r   ÚwriteÚlenr   r   r   )r   ÚsizeÚbuf_sizeÚchunkr   Ú	remainings         r   r   zAsyncUnreader.read6   sq  è ø€ ð Ð¤J¨t´SÔ$9ÜÐDÓEÐEàÐØ�qŠyØØ�aŠxØ�à×$Ñ$Ó&ˆð ˆ<˜H qšLØ×*Ñ*Ó,Ð,Øˆ<Ø×*Ñ*Ó,×,ˆEØˆLð ˜ŠoØ×*Ñ*Ó,×,ˆEÙØ×.Ñ.Ó0Ð0Ø�H‰H�M‰M˜!œRŸ[™[Ô)Ø�H‰H�N‰N˜5Ô!Øœ˜E›
Ñ"ˆHð ˜‹oð 	�‰�‰�d—o‘oÔ&Ø�x‰x�}‰}˜TÓ"ˆð 	�Š˜4Ñ�ð �?‰?˜TÒ!ØŸ™Ÿ™›ˆIØ×ÑÔ ÙØ—‘—‘˜yÔ)àˆð5 -ùð
 -ûs,   ‚A)F-Á+F'Á,F-Â
F*ÂA.F-Ã:B.F-Æ*F-c              ƒ   óˆ   K  — 	 | j                   j                  | j                  «      ƒ d{  –—† S 7 Œ# t        $ r Y yw xY w­w)z0Read a chunk of data from the underlying stream.Nr   )r   r   r
   Ú	Exceptionr   s    r   r"   zAsyncUnreader._read_chunkk   s;   è ø€ ð	ØŸ™×)Ñ)¨$¯.©.Ó9×9Ð9Ð9ùÜò 	Ùð	üs,   ‚A„(3 ¬1­3 °A±3 ³	?¼A¾?¿Ac                 ó  — |r‰| j                   j                  | j                  «       | j                   j                  «       }| j	                  «        | j                   j                  |«       |r| j                   j                  |«       yyy)zµPush data back into the buffer for re-reading.

        Args:
            data: bytes to push back

        Note: This prepends data to the buffer so it will be read first.
        N)r	   r   r   r   r   r#   )r   r   Úexistings      r   ÚunreadzAsyncUnreader.unreadr   se   € ñ à�H‰H�M‰M˜$Ÿ/™/Ô*Ø—x‘x—}‘}“ˆHð ×ÑÔ Ø�H‰H�N‰N˜4Ô ÙØ—‘—‘˜xÕ(ð ð r   c                 ó(   — | j                  «       dkD  S )z-Check if there's data in the pushback buffer.r   )r   r   s    r   Úhas_buffered_datazAsyncUnreader.has_buffered_data…   s   € à× Ñ Ó" QÑ&Ð&r   )r   )N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r"   r-   r/   © r   r   r   r      s0   „ ñó
òòò%ó
3òjò)ó&'r   r   )r3   r   r   r4   r   r   ú<module>r5      s   ðñ
ó 
÷y'ò y'r   